3 ms·
I use http://chriswarbo.net/projects/activecode http://chriswarbo.net/projects/activecode for my web site, which is a slightly different take on literate progra
by chriswarbo 5y ago
I use http://chriswarbo.net/projects/activecode http://chriswarbo.net/projects/activecode for my web site, which is a slightly different take on literate programming. Rather than being hard-coded to a particular programming language, it instead just pipes stdio through shell commands (which includes interpreters/compilers for any language we like).
It also uses Pandoc, so supports lots of input and output formats (Markdown, LaTeX, HTML, etc.). For example, this Markdown will generate a list of numbers, along with a code listing:
The following list:
```{.unwrap pipe="tee example.py | python3 | pandoc -f md -t json"}
for i in range(10):
print(' - ' + str(i))
```
Was generated using this code:
```{.python pipe="cat example.py"}
```
The first code block gets run through the command given by `pipe`: that saves a copy of the code to `example.py`, interprets it using `python3`, then uses `pandoc` to convert the generated Markdown to "Pandoc JSON" format. That JSON replaces the original contents of the code block, and the `.unwrap` tells Pandoc to replace the code block with its contents (parsed as Pandoc JSON).
The second code block gets run through the command `cat example.py`, which ignores its input (which is empty anyhow), and dumps out the `example.py` file that was generated by the first code block. The `.python` tells Pandoc to syntax-highlight this block as Python code.
- smasher164 5y agoThis is similar to the approach I take in my markup language: https://github.com/smasher164/mexdown https://github.com/smasher164/mexdown. Pipe the body of a code block to the command's stdin, and replace the code block with its output.
- khalidx 5y agoInteresting, going to check this out today. I built something in a similar spirit to your comment and this larger thread, albeit a bit simplistic. Lets you document and write your bash scripts in a markdown file, then you can run the blocks. It figures out what arguments you expect in a block and turns them into CLI flags. https://github.com/khalidx/runbook https://github.com/khalidx/runbook Not sure how useful it is but I use it to maintain a collection of documented bash scripts.