The mmark-filter command allows you to rewrite the input markdown to new markdown.
Right now it contains a couple of plugins, of which the exec plugin is the most interesting one.
Exec
The exec plugin will check if a code block has a exec:CMD
language tag. If found the the
following steps will be performed:
-
CMD
will be executed with the contents of the code block piped to it’s standard input. -
The ouput from
CMD
(if any) will be used to construct a data URI. -
The code block will then be deleted and replaced with an image containing the data URI.
Usage
Say you have the following little script that calls dot
:
#!/bin/bash
dot -Tpng
And this markdown:
This was code block:
``` exec:./dot.sh
digraph D {
A [shape=diamond]
B [shape=box]
C [shape=circle]
A -> B [style=dashed, color=grey]
A -> C [color="black:invis:black"]
A -> D [penwidth=5, arrowhead=none]
}
```
Note the exec:./dot.sh
line that tells the filter to run dot.sh
with the contents of the
codeblock. Putting this in a test.md
file, you can then run:
./filter -p exec < test.md | mmark -html > out.html
With the HTML looking like:
Protocol
The protocol plugin can be used to run protocol that allows for generating ASCII-art protocol diagrams for code blocks.
Just put the command line you need to run for protocol
in a code block, set the language to
“protocol” and run the filter. It will then replace the code block’s content with the output from
protocol, i.e. the generated diagram.
Usage
This markdown file:
We describe the following protocol:
``` protocol
Source:16,TTL:8,Reserved:40
```
Figure: This is a protocol.
Will be transformed with filter -p protocol < protocol.md
, to:
We describe the following protocol:
```
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source | TTL | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
```
Figure: This is a protocol.