A script that concatenates all the code blocks in a Markdown file and runs the resulting file.
- Write some Markdown with embedded code:
# Hello, world! ```python print("Hello, world!") x = 3 ``` Some text ```python print("Here's more code!") print(x) ```
- Run the script
$ python3 runmd.py input_file.md python --exec python3 Hello, world! Here's more code! 3
Untagged code blocks can be included with --untagged
. Use --exec cmd
if the name of the language doesn't match the command to execute
it. python3 runmd.py --help
for more information.
The error code of runmd
is the same as the error code of the
executed script.
RunMD scans the input file for fenced code blocks with an info string indicating the correct language (see https://spec.commonmark.org/0.29/#fenced-code-blocks). It then concatenates all code blocks of that language into a temporary file and executes that file.