A Rust preprocessor for mdBook, replacing regular expression patterns with specified strings. Regex syntax is based on the Regex Rust crate.

Usage

Install the crate

cargo install mdbook-regex

Specify the patterns and string replacement in a .json file

json [ { "pattern" : "Your Pattern", "template" : "Your Template" } ]

Add the preprocessor to your book.toml file, and specify the path of the .json patterns file

toml [preprocessor.regex] patterns = "path/to/patterns.json"

Example

For example, the following pattern

json [ { "pattern" : "collapse:(?P([^\n])<em>)\n(?P<content>(?s:.)</em>)\n<code>", "template" : "<details>\n<summary>${title}</summary>\n<div class='collapsed'>\n${content}\n</div>\n</details>" } ] </code></p> <p>allows the creation of collapsible regions, turning this</p> <p><code>text ``collapse:Title Content `` </code></p> <p>into this </p> <p>```text <details> <summary>Title</summary></p> <div class='collapsed'> Content </div> <p></details> ```</p> </body></html>