10 releases (5 stable)
1.1.0 | Apr 23, 2024 |
---|---|
1.0.3 | Apr 23, 2024 |
0.1.0 | Mar 25, 2024 |
0.0.3 | Nov 10, 2023 |
#95 in Text processing
506 downloads per month
26KB
302 lines
Yet another preprocessor for mdBook
Overview
A mdbook
preprocessor that simply replaces text in chapters.
Phrases to be replaced with specified content are defined in plain-text configuration file.
Installation
Install using Cargo:
$ cargo install mdbook-yapp
Configure this preprocessor by adding to your book.toml
the following line:
[preprocessor.yapp]
Build you book as usual:
$ mdbook build
There should be a warning message displayed when no configuration file is found.
2023-11-11 12:01:02 [INFO] (mdbook::book): Book building has started
[WARNING][Yapp] configuration file not found, in current directory expected a file with the name starting with prefix: yapp
[WARNING][Yapp] configuration file not found, in current directory expected a file with the name starting with prefix: yapp
2023-11-11 12:01:03 [INFO] (mdbook::book): Running the html backend
Prepare the configuration file as described in the next section.
Configuration
This preprocessor requires single configuration file in plain-text format.
This file's name should start with the prefix yapp
. Letter case is not significant.
So names like yapp
, Yapp
, Yappi
, yapp.config
and similar will do.
Configuration file must contain pairs of lines of text.
First line is the phrase to be searched in the chapter and the second line is the replacement.
Having a configuration file named yapp.config
with the following content:
jd
John Doe
will inform this preprocessor to search for all jd
instances in all chapters of the book
and to replace them with the text John Doe
.
Configuration files may have empty lines, which are ignored. Empty lines may make the configuration more readable when there are multiple replacements defined, like this:
jd
John Doe
^note
**Note**:
@version
1.23.4
Replacements are done in the order defined in configuration file, so the substitutions may be chained, like this:
a
ab
ab
abb
abb
abba
abba
ABBA
Every letter a
in all chapters will be replaced with ABBA
.
Note that each line in configuration file is trimmed before used. So configuration file with the content like this:
a
ab
ab
abb
abb
abba
abba
ABBA
will have the same effect as the file in the previous example.
To preserve whitespaces in search pattern or replacement, enclose it in a single quotation mark:
' a '
' b c '
or double quotation mark:
" a "
" b c "
so the result of replacement for input │ a │
will be │ b c │
.
License
Licensed under either of
- MIT license (see LICENSE-MIT) or
- Apache License, Version 2.0 (see LICENSE and NOTICE)
at your option.
Contribution
All contributions intentionally submitted for inclusion in the work by you, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~12–22MB
~332K SLoC