Introduce Preprocessors #530
Labels
A-Internal-representation
Area: Internal Representation
C-enhancement
Category: Enhancement or feature request
E-Help-wanted
Experience: Help Needed
E-Medium
Experience: Medium
Milestone
Uh oh!
There was an error while loading. Please reload this page.
As part of the overall effort to make
mdbook
more modular, it'd be nice to formalise the concept of a "preprocessor". This is a bit of code that's run immediately after aBook
is loaded from disk and before it gets rendered, allowing you to apply manipulations/transformations to the original source code.Use cases are:
{{#playpen file.rs}}
and{{#include file.md}}
"macros"$$ ... $$
snippet with its mathjax equivalentRough guideline of what is involved:
Preprocessor
traitMDBook
hold a list of preprocessors (Vec<Box<Preprocessor>>
) and add awith_preprocessor()
method for adding more{{#playpen ...}}
and{{#include ...}}
(from here) into their own preprocessor types instead of being run as part of the HTML renderer (here)MDBook::build()
process, execute each preprocessor on a copy of the originalBook
MDBook::load_with_config()
so we can discover which preprocessors should be run by inspecting thebook.toml
configIt looks like a big job, but that's mainly because there are several little steps which need to be tweaked. Steps 1 and 3 are actually just a dozen lines, with step 5 being the most complex (and even then you can steal 90% of the work from existing code). I'd estimate this to be a couple hundred lines of code at most, with a large proportion of that being taken up by relatively straight-forward tests and documentation.
I'm also more than happy to help mentor through the entire process 😀
The text was updated successfully, but these errors were encountered: