PreprocessorContext does not allow preprocessor to obtain the section name that triggered its invocation
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 22.2k
- Forks
- 1.9k
- PR merge metrics
- PR metrics pending
Description
Problem
It is handy to invoke a subprocessor multiple times, for example before/after links or to perform different iterations.
Similar to os argv[0], it is handy to know the invocation name to be able to be able to refer back and obtain unique behavior.
Please refer to the following example:
[preprocessor.variables-pre]
command = "@MDBOOK_VARIABLES_EXECUTABLE@"
before = [
"links",
]
[preprocessor.variables]
command = "@MDBOOK_VARIABLES_EXECUTABLE@"
after = [
"links",
]
[preprocessor.variables.variables]
BUILD_DIR = "@CMAKE_BINARY_DIR@"
The variables subprocessor has no way to know what section invoked it, it must go back to configuration and read a static section, in this case both instances of invocation refer back to the same configuration.
Proposed Solution
Pass the section name of invocation to the preprocessor context so that the preprocessor may be able to access its own section for obtaining configuration or to derive other instance based sections.
#[non_exhaustive]
pub struct PreprocessorContext {
pub root: PathBuf,
pub config: Config,
pub renderer: String,
pub mdbook_version: String,
pub chapter_titles: RefCell<HashMap<PathBuf, String>>,
+ pub section: String,
}
In the command-line protocol, it will be very nice to obtain the configuration file name and the section name as environment variables to be able to apply the same pattern.
Notes
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing PreprocessorContext and the command-line protocol to find where the invoking section is available and where context is constructed. Done means a preprocessor can identify the section that invoked it, with the proposed configuration-file and section environment variables addressed or explicitly scoped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100