#regex #pattern #string #replacing #expression #regular #template

app mdbook-regex

Mdbook preprocessor replacing regular expression patterns with specified strings

2 releases

0.0.2 Nov 20, 2020
0.0.1 Nov 20, 2020

#10 in #replacing

MIT license

15KB
116 lines

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

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

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

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

Example

The following pattern

[
    {
        "pattern" : "``collapse:(?P<title>([^\n])*)\n(?P<content>(?s:.)*)\n``",
        "template" : "<details>\n<summary>${title}</summary>\n<div class='collapsed'>\n${content}\n</div>\n</details>"
    }
]

allows the creation of collapsible regions, turning this

``collapse:Title
Content
``

into this

<details>
<summary>Title</summary>
<div class='collapsed'>
Content
</div>
</details>

Dependencies

~13–24MB
~350K SLoC