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

Add support for Pandoc Markdown #327

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 2 deletions doc/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,9 @@ 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`).
- [pandoc](https://pandoc.org/), a Markdown processor with an extensive feature set (see [here](https://pandoc.org/installing.html) for installation and make sure `pandoc` is on `PATH`).

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|pandoc|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 Expand Up @@ -1184,7 +1185,7 @@ of files and directories.
- `title` page title, default 'Reference'
- `package ` explicit base package name; also used for resolving references in documents
- `all` show local functions, etc as well in the docs
- `format` markup processor, can be 'plain' (default), 'markdown' or 'discount'
- `format` markup processor, can be 'plain' (default), 'markdown', 'discount', 'lunamark' or 'pandoc'
- `output` output name (default 'index')
- `dir` directory for output files (default 'doc')
- `colon` use colon style, instead of @ tag style
Expand Down
9 changes: 9 additions & 0 deletions ldoc/html/_code_css.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ pre .user-keyword { color: #800080; }
pre .prompt { color: #558817; }
pre .url { color: #272fc2; text-decoration: underline; }

/* same, for Pandoc code highlighting */
code span.co { color: #558817; }
code span.cn { color: #a8660d; }
code span.kw, code span.cf { color: #aa5050; font-weight: bold; }
code span.st { color: #8080ff; }
code span.dv { color: #f8660d; }
code span.pp { color: #a33243; }
code span.va { color: #800080; }

]]
14 changes: 14 additions & 0 deletions ldoc/markup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,20 @@ local formatters =
{ smart = true })
return function(text) return parse(text) end
end
end,
pandoc = function(format)
return function(text)
local out_filename = os.tmpname()
local in_file = io.popen("pandoc -f markdown -t html -o " .. out_filename .. " -", "w")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this PR looks good and I'd love to see it merged, but this bit of coding seems counter intuitive to me. You're writing to something called "in_file" and reading from "out_file" — but it's really tricky to realize whose perspective on in and out is being used here. I suggest using names that better represent what they are ... tmpfile, stdin or fifo or some such?

Otherwise I'll give this a test drive and make sure it works, then merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe markdown_file and html_file (based on the contents)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that sounds clear.

in_file:write(text)
in_file:close()

local out_file = io.open(out_filename, "rb")
local out_content = out_file:read("*all")
out_file:close()
os.remove(out_filename)
return out_content
end
end
}

Expand Down