mdbook-cmdrun
This is a preprocessor for the rust-lang mdbook project. This allows to run arbitrary (shell) commands and include the output of these commands within the markdown file.
Getting started
You also have to activate the preprocessor, put this in your book.toml file:
[]
:warning: This preprocessor presents a security risk, as arbitrary commands can be run. Be careful with the commands you run. To list all the commands that will be run within an mdbook, you can run the following command:
|
How to
Let's say we have these two files:
Markdown file: file.md
Python file: script.py
The preprocessor will call seq then python3, and will produce the resulting file:
1
2
3
4
5
6
7
8
9
10
This comes from the script.py file
Since I'm in a scripting language,
I can compute whatever I want
Details
When the pattern <!-- cmdrun $1 -->\n or <!-- cmdrun $1 --> is encountered, the command $1 will be run using the shell sh like this: sh -c $1.
Also the working directory is the directory where the pattern was found (not root).
The command invoked must take no inputs (stdin is not used), but a list of command lines arguments and must produce output in stdout, stderr is ignored.
As of July 2023, mdbook-cmdrun runs on Windows platforms using the cmd shell!
Examples
The following is valid:
```rust
```
```diff
```
```console
```
````markdown
Which gets rendered as:
Some more examples are implemented, and are used as regression tests. You can find them here. At the moment of writing, there are examples using:
- Shell
- Bash script
- Batch script
- Python3
- Node
- Rust
Contributors
I would like to thank @exsjabe for his valuable help with integrating Windows support and inline cmdrun calls.
Current version: 0.6.0
License: MIT