Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the use of commonmark markdown via cmark-lua #311

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ldoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions ldoc/markup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down