mdbook_CodeChat.py - A CodeChat preprocessor for mdbook¶
mdbook allows preprocessors to modify the provided source before processing it with a Markdown engine. This preprocessor transforms source code in files collected by mdbook into Markdown based on CodeChat.
See the mdbook template for an example of how to integrate CodeChat with mdbook.
See the mdbook docs on configuring preprocessors and preprocessors in the For Developers chapter for more information.
Imports¶
These are listed in the order prescribed by PEP 8.
Standard library¶
Third-party imports¶
Local application imports¶
Code¶
This is the heart of the program: given a list of sub_items
, walk the list, transforming source code to Markdown.
If this is a chapter, instead of a section title / separator / etc., process it. (Note that separators aren’t a dict, but instead the string “Separator”.)
Don’t process Markdown files. Try everything else.
See if it’s an extension we should process.
See if source_file
matches any of the globs.
On a match, pass the specified lexer alias.
Do this after checking the lexer_for_glob
list, since this will raise an exception on failure.
We don’t support this language.
Return True if the provided filename is a source code language CodeChat supports.
main¶
See if this is asking for renderer support, or for an actual render.
Renderer support – html only.
Delay imports until this point, so the first phase of the build (detecting support, which is handled above) can run without these. Load both the context and the book representations from stdin.
Get the lexer_for_glob dict.
Walk through each file, rendering it if possible.
Dump the updated book back to mdbook via stdout.