ANN: lcmark = cmark + YAML metadata + templates + lua filters

I’ve released a lua library and command-line program, lcmark. If you have lua and luarocks, you can install lcmark easily with

luarocks install lcmark

lcmark does what the cmark program does (parsing CommonMark and producing output in HTML, LaTeX, man, XML, or CommonMark), with the following enhancements:

  • Support for YAML metadata at the top of the document. The metadata is parsed as CommonMark and returned in a table (dictionary) that will set template variables.

  • Support for templates, which add headers and footers around the body of the document, and can include variables defined in the metadata. The template format is the one used in pandoc, so pandoc templates can be used.

  • Support for lua filters, which allow the document to be transformed between parsing and rendering, making possible a great many customizations.

I have a few sample filters here, but much more is possible. For example, it is easy to write a filter that replaces specially marked code blocks with images produced by a program like graphviz.

lcmark depends on the lua cmark library, which wraps the reference implementation (libcmark) but extends it in ways that make it easier to use the cmark API in lua. cmark comes with a “builder” module that allows you to construct documents programatically, for example,

local b = require'cmark.builder'
local mydoc = b.document{
                b.paragraph{
                  "Hello ", b.emph "world",
                  b.link{ url="http://example.com", "!"} }}
1 Like