A CLI Tool for Executing Code Blocks in Markdown Files.
RunMD is a command-line tool designed to extract and execute code blocks from Markdown files. It's particularly useful for managing and running code snippets embedded in documentation or notes.
⚠ RunMD is intended for use with scripting languages only (e.g., Shell, Python, Ruby, JavaScript). It does not support compiled languages (e.g., C, C++, Java) as it cannot handle compilation and execution steps.
⚠ RunMD is different from interactive notebooks like Jupyter or Zepplin. Each code block is independent and executed separately.
Prerequisites
Before you begin, ensure you have the following installed:
- Python 3.9 or later
- pip (Python package installer)
- Git (for cloning the repository)
Installation
From Python Package Index
pip install runmd
From GitHub release
pip install git+https://github.com/PageotD/runmd@0.10.1
From source
Clone the GitHub repository:
git clone https://github.com/PageotD/runmd.git
cd runmd
Install Build and Wheel Dependencies:
pip install build wheel
Build and Install RunMD
python -m build
pip install dist/runmd-<version>-py3-none-any.whl
Initialize
runmd init
Usage
Synopsis
runmd [COMMAND] [OPTIONS]
Commands
RUN
Executes specified code blocks in a Markdown file.
runmd run [blockname] [--tag TAG] [--file FILE] [--env VAR=value ...]
blockname: The name of the code block to run, or "all" to run all blocks.-t [TAG], --tag [TAG]: Specify the tag of the code blocks to run.-f [FILE], --file [FILE]: Specify the path to the Markdown file containing the code blocks.--env VAR=value ...: Optional environment variables to set during the execution.
SHOW
Displays the content of a specified code block.
runmd show [blockname] [--file FILE]
blockname: The name of the code block to display.-f [FILE], --file [FILE]: Specify the path to the Markdown file.
LIST
Lists all the code blocks in a Markdown file.
runmd list [tag] [--file FILE]
-t [TAG], --tag [TAG]: Optional tag to filter the list of code blocks.-f [FILE], --file [FILE]: Specify the path to the Markdown file.
HIST
Displays or clears the history of runmd commands.
runmd hist [id] [--clear]
id: command line entry in history to execute.--clear: Clears definitely all the command line entries in history.
VAULT
Encrypt/Decrypt a markdown file using a password.
runmd vault --encrypt README.md --outfile README.enc
runmd vault --decrypt README.enc --outfile README.dec
-e [FILE], --encrypt [FILE]: Encrypt the specified markdown file.-d [FILE], --decrypt [FILE]: Decrypt the encrypted file.-o [FILE], --outfile [FILE]: Optional output file name (default: add.vaultsuffix to input file name).
Other options
Other options are quite standard:
--help: to show the help message--version: to get the installed version of runmd
Display the version of
Add executable code block
To add an executable code block to your Markdown file, use the following syntax:
# My executable code block
```sh {name=export-echo,tag=example}
EXPORT MYSTR="a simple export and echo"
echo $MYSTR
```
List Code Blocks
To list all code block names in Markdown files within the current directory:
runmd list
Show a Specific Code Block
To display the content of a specific code block:
runmd show <code-block-name>
Run a Specific Code Block
To execute a specific code block by name:
runmd run <code-block-name>
Run all code blocks with a given tag
To execute a specific code block by name:
runmd run -t <tag>
Run all code blocks
To execute a specific code block by name:
runmd run all
Run a Specific Code Block with nvironment variable
To execute a specific code block by name:
runmd run <code-block-name> --env <KEY1>=<VALUE1> <KEY2=VALUE2>
Run all code blocks
To execute all code blocks in Markdown files within the current directory:
runmd run all
Configuration
You can customize how different scripting languages are executed by creating a configuration file at ~/.config/runmd/config.json. Here’s an example configuration:
{
"sh": {
"command": "bash",
"options": ["-c"]
},
"python": {
"command": "python",
"options": []
},
"ruby": {
"command": "ruby",
"options": []
}
}
Troubleshooting
- No Output: Ensure the Markdown code blocks are correctly formatted and the specified commands are valid for the environment.
- Permission Denied: Check if you have the required permissions to execute the commands in the code blocks.
Metadata
Release files for runmd 0.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| runmd-0.16.0.tar.gz | 26.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| runmd-0.16.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.5 kB
Release files / runmd-0.16.0.tar.gz
| Download URL | runmd-0.16.0.tar.gz |
|---|---|
| Size | 26.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
826dc2f5ab09276e1e7c93d62ed3f0996076f7a49e4a95acebc69729e9375cce
|
|
BLAKE2b-256 checksum How to use checksums |
6c4010a78e9a40ae78c592945493f6cfcb415e34b08ef3a5b9912fd9b60ef08e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2024.
Transparency logRelease files / runmd-0.16.0-py3-none-any.whl
| Download URL | runmd-0.16.0-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7834849e43bc436ce01beba1a1efa4461c3264d6c83e46c0ba2f711c80a8386
|
|
BLAKE2b-256 checksum How to use checksums |
9e32634fd6e55692bc5a5fd71404b1e070adecff6a3a06a96152c30e5a6130b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2024.
Transparency log