Mmark markdown filters

2 minute read Published:

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.


The exec plugin will check if a code block has a exec:CMD language tag. If found the the following steps will be performed:

  1. CMD will be executed with the contents of the code block piped to it’s standard input.

  2. The ouput from CMD (if any) will be used to construct a data URI.

  3. The code block will then be deleted and replaced with an image containing the data URI.


Say you have the following little script that calls dot:

dot -Tpng

And this markdown:

This was code block:

``` exec:./
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:./ line that tells the filter to run with the contents of the codeblock. Putting this in a file, you can then run:

./filter -p exec < | mmark -html > out.html

With the HTML looking like:


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.


This markdown file:

We describe the following protocol:

``` protocol
Figure: This is a protocol.

Will be transformed with filter -p protocol <, 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.