rust-lang / rust-lang/mdBook

PreprocessorContext does not allow preprocessor to obtain the section name that triggered its invocation

Open
#3,029 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-Preprocessor C-enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.