# markdown-code-runner
A Rust implementation of [markdown-code-runner](https://github.com/basnijholt/markdown-code-runner) - automatically update Markdown files with code block output.
## Installation
```bash
cargo install markdown-code-runner
```
Or build from source:
```bash
git clone https://github.com/basnijholt/markdown-code-runner-rs
cd markdown-code-runner-rs
cargo install --path .
```
## Usage
```bash
markdown-code-runner [OPTIONS] <INPUT>
Arguments:
<INPUT> Path to the input Markdown file
Options:
-o, --output <OUTPUT> Path to the output Markdown file (default: overwrite input file)
-d, --verbose Enable verbose/debug mode
--no-backtick-standardize Disable backtick standardization
-s, --standardize Post-process to standardize ALL code fences
-n, --no-execute Skip code execution entirely
-h, --help Print help
-V, --version Print version
```
## Markdown Syntax
### Backtick Code Blocks
Add `markdown-code-runner` after the language identifier to mark a code block for execution:
~~~markdown
```python markdown-code-runner
print('Hello, world!')
```
This will be replaced by the output.
~~~
### Hidden Code Blocks (HTML Comments)
Use HTML comments to hide the code while still executing it:
```markdown
This will be replaced by the output.
```
For Bash:
```markdown
This will be replaced by the output.
```
### Skip Marker
Use `<!-- CODE:SKIP -->` to prevent execution of the next code block:
~~~markdown
```python markdown-code-runner
print('This will not be executed')
```
This output will be preserved.
~~~
### Write to File
Use the `filename=` option to write code to a file instead of executing:
~~~markdown
```rust markdown-code-runner filename=example.rs
fn main() {
println!("Hello, Rust!");
}
```
~~~
## Variable Persistence
Variables defined in Python code blocks are shared across all subsequent Python blocks in the same file:
~~~markdown
```python markdown-code-runner
x = 42
print(x)
```
42
```python markdown-code-runner
print(x * 2)
```
84
~~~
## Indented Code Blocks
Code blocks in list items or other indented contexts are supported:
~~~markdown
1. Example:
```python markdown-code-runner
print('indented')
```
indented
~~~
## License
MIT License - see [LICENSE](LICENSE) for details.
## Related
- [markdown-code-runner](https://github.com/basnijholt/markdown-code-runner) - The original Python implementation