diff --git a/doc/doc.md b/doc/doc.md index 683d93c2..64a113b0 100644 --- a/doc/doc.md +++ b/doc/doc.md @@ -754,8 +754,11 @@ Niklas Frykholm. For convenience, LDoc comes with a copy of markdown.lua. more features than the pure Lua version, such as PHP-Extra style tables. - [lunamark](http://jgm.github.com/lunamark/), another pure Lua processor, faster than markdown, and with extra features (`luarocks install lunamark`). + - commonmark via [cmark-lua](https://github.com/jgm/cmark-lua), a Lua wrapper +around the fast [libcmark](https://github.com/jgm/cmark) C library (`luarocks +install cmark`) -You can request the processor you like with `format = 'markdown|discount|lunamark|plain|backticks'`, and +You can request the processor you like with `format = 'markdown|discount|lunamark|commonmark|plain|backticks'`, and LDoc will attempt to use it. If it can't find it, it will look for one of the other markdown processors; the original `markdown.lua` ships with LDoc, although it's slow for larger documents. diff --git a/ldoc.lua b/ldoc.lua index 4cb99663..aee3499c 100644 --- a/ldoc.lua +++ b/ldoc.lua @@ -49,7 +49,7 @@ ldoc, a documentation generator for Lua, vs ]]..version..[[ -l,--template (default !) directory for template (ldoc.ltp) -p,--project (default ldoc) project name -t,--title (default Reference) page title - -f,--format (default plain) formatting - can be markdown, discount or plain + -f,--format (default plain) formatting - can be markdown, discount, lunamark, commonmark, backticks, or plain -b,--package (default .) top-level package basename (needed for module(...)) -x,--ext (default html) output file extension -c,--config (default config.ld) configuration name diff --git a/ldoc/markup.lua b/ldoc/markup.lua index e34286d5..59783cdf 100644 --- a/ldoc/markup.lua +++ b/ldoc/markup.lua @@ -275,6 +275,15 @@ local formatters = { smart = true }) return function(text) return parse(text) end end + end, + commonmark = function(format) + local ok, cmark = pcall(require, 'cmark') + if ok then + return function(text) + local doc = cmark.parse_document(text, string.len(text), cmark.OPT_DEFAULT) + return cmark.render_html(doc, cmark.OPT_DEFAULT) + end + end end }