Skip to content

Commit 77e72bf

Browse files
authored
Support the use of commonmark markdown via cmark-lua (#311)
1 parent 794fd0e commit 77e72bf

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/doc.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,11 @@ Niklas Frykholm. For convenience, LDoc comes with a copy of markdown.lua.
754754
more features than the pure Lua version, such as PHP-Extra style tables.
755755
- [lunamark](http://jgm.github.com/lunamark/), another pure Lua processor, faster than
756756
markdown, and with extra features (`luarocks install lunamark`).
757+
- commonmark via [cmark-lua](https://github.com/jgm/cmark-lua), a Lua wrapper
758+
around the fast [libcmark](https://github.com/jgm/cmark) C library (`luarocks
759+
install cmark`)
757760

758-
You can request the processor you like with `format = 'markdown|discount|lunamark|plain|backticks'`, and
761+
You can request the processor you like with `format = 'markdown|discount|lunamark|commonmark|plain|backticks'`, and
759762
LDoc will attempt to use it. If it can't find it, it will look for one of the other
760763
markdown processors; the original `markdown.lua` ships with LDoc, although it's slow
761764
for larger documents.

ldoc.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ldoc, a documentation generator for Lua, vs ]]..version..[[
4949
-l,--template (default !) directory for template (ldoc.ltp)
5050
-p,--project (default ldoc) project name
5151
-t,--title (default Reference) page title
52-
-f,--format (default plain) formatting - can be markdown, discount or plain
52+
-f,--format (default plain) formatting - can be markdown, discount, lunamark, commonmark, backticks, or plain
5353
-b,--package (default .) top-level package basename (needed for module(...))
5454
-x,--ext (default html) output file extension
5555
-c,--config (default config.ld) configuration name

ldoc/markup.lua

+9
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ local formatters =
275275
{ smart = true })
276276
return function(text) return parse(text) end
277277
end
278+
end,
279+
commonmark = function(format)
280+
local ok, cmark = pcall(require, 'cmark')
281+
if ok then
282+
return function(text)
283+
local doc = cmark.parse_document(text, string.len(text), cmark.OPT_DEFAULT)
284+
return cmark.render_html(doc, cmark.OPT_DEFAULT)
285+
end
286+
end
278287
end
279288
}
280289

0 commit comments

Comments
 (0)