Golden Rule
All code blocks must be executable. Never write illustrative/pseudo code blocks. If you’re showing an API usage pattern, create a minimal working example that actually runs. This ensures documentation stays correct as the codebase evolves.Running
skip
Supported Languages
Python, Shell (sh), Node.js, plus visualization: Matplotlib, Graphviz, Pikchr, Asymptote, OpenSCAD, Diagon.Code Block Flags
Add flags after the language identifier:| Flag | Effect |
|---|---|
session=NAME | Share state between blocks with same session name |
output=path.png | Write output to file instead of inline |
no-result | Execute but don’t insert result |
skip | Don’t execute this block |
expected-error | Block is expected to fail |
skip when a block would pull in CUDA / GPU-only stacks (for example perception models, VoxelGridMapper defaults, or imports that load torch with GPU expectations), or when it is flaky in CI (multi-module coordinators, timing-sensitive workers, pytest-style snippets that are not meant to run as a single script). Prefer expected-error only when the block is supposed to fail and you want to assert that failure.
Examples
md-babel-py
Execute code blocks in markdown files and insert the results.
Use cases:
- Keep documentation examples up-to-date automatically
- Validate code snippets in docs actually work
- Generate diagrams and charts from code in markdown
- Literate programming with executable documentation
Languages
Shell
Python
session=example
session=example
Node.js
Matplotlib
output=assets/matplotlib-demo.svg
Pikchr
SQLite’s diagram language:Asymptote
Vector graphics:output=assets/histogram.svg
Graphviz
output=assets/graph.svg
Diagon
ASCII art diagrams:mode=Math
mode=GraphDAG
Install
Nix (recommended)
skip
Docker
skip
pipx
skip
| Language | System packages |
|---|---|
| python | python3 |
| node | nodejs |
| dot | graphviz |
| asymptote | asymptote, texlive, dvisvgm |
| pikchr | pikchr |
| openscad | openscad, xvfb, imagemagick |
| diagon | diagon |
skip
Usage
skip
