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

DRAFT: HTML support #18

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 10 additions & 1 deletion inputters/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,18 @@ local function SileAstWriter (options)
writer.blockquote = simpleCommandWrapper("markdown:internal:blockquote")
writer.verbatim = simpleCommandWrapper("verbatim")
writer.listitem = simpleCommandWrapper("item")
writer.linebreak = simpleCommandWrapper("cr")
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this removed? We'd still want to support the standard Markdown linebreaks.

Copy link
Author

Choose a reason for hiding this comment

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

Mistake during testing thanks

writer.singlequoted = simpleCommandWrapper("singlequoted")
writer.doublequoted = simpleCommandWrapper("doublequoted")

writer.inline_html = function(args)
local htmlroot = htmlparser.parse(args)
if #htmlroot.nodes > 0 then
local rootname = htmlroot.nodes[1].name
SU.debug("markdown", "Got raw HTML w/root tag: " .. rootname)
return utils.createCommand("markdown:html:" .. rootname)
end
end

-- Special case for hrule (simple too, but arguments from lunamark has to be ignored)
writer.hrule = function () return utils.createCommand("fullrule") end

Expand Down Expand Up @@ -305,6 +313,7 @@ end
function inputter.parse (_, doc)
local lunamark = require("lunamark")
local reader = lunamark.reader.markdown
htmlparser = require("htmlparser")
local writer = SileAstWriter({
layout = "minimize" -- The default layout is to output \n\n as inter-block separator
-- Let's cancel it completely, and insert our own \par where needed.
Expand Down
3 changes: 2 additions & 1 deletion markdown.sile-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ dependencies = {
"lua >= 5.1",
"ptable.sile",
"textsubsuper.sile",
"smartquotes.sile"
"smartquotes.sile",
"htmlparser",
}

build = {
Expand Down
7 changes: 5 additions & 2 deletions packages/markdown/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--
local utils = require("packages.markdown.utils")
local base = require("packages.base")
local html = require("packages.markdown.html")
Copy link
Owner

Choose a reason for hiding this comment

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

In packages/markdown/init.lua you are loading it via the class, so there wouldn't be any reason to load it too via require(), is there? (and the commands would be registered via the class if you rename your registerHTMLcommands to registerCommands, simply.


local package = pl.class(base)
package._name = "markdown.commands"
Expand Down Expand Up @@ -364,7 +365,10 @@ function package:registerCommands ()
SILE.call("smallskip")
end, "A fallback command for Markdown to insert a captioned table")

-- C. Customizable hooks
-- C. HTML commands
html.registerHTMLcommands(self)

-- D. Customizable hooks

self:registerCommand("markdown:custom-style:hook", function (options, content)
-- Default implementation for the custom-style hook:
Expand All @@ -386,7 +390,6 @@ function package:registerCommands ()
end
end
end, "Default hook for custom style support in Markdown")

end

package.documentation = [[\begin{document}
Expand Down
44 changes: 44 additions & 0 deletions packages/markdown/html.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local base = require("packages.base")
local utils = require("packages.markdown.utils")

local package = pl.class(base)
package._name = "markdown.html"

local passthroughs = {
"sup",
Copy link
Owner

Choose a reason for hiding this comment

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

SILE does not have these, right? We'd need to map them

  • to raise/lower (in the general case)
  • or perhaps even, initially to the package-provided textsuperscript/textsubscript (if containing only text).

Copy link
Author

Choose a reason for hiding this comment

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

It has them.

Copy link
Owner

Choose a reason for hiding this comment

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

It doesn't seem so (at least, there's no "sup"/"sub" in the base and plain class), they only exist it seems in math mode.

Copy link
Author

Choose a reason for hiding this comment

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

Heh, with all due respect, you do so much work it seems you forget some of it!

self.class:loadPackage("textsubsuper")

Copy link
Owner

Choose a reason for hiding this comment

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

Heh, with all due respect, you do so much work it seems you forget some of it!

Heh :) But in that case the commands are textsuperscript and textsubscript then (not sup and sub, hence my initial question).

In the current implementation, they'd work if the content is text-only. (If it's not, they ought to fail, although we may reconsider our options)

Copy link
Author

Choose a reason for hiding this comment

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

Huh, strange, my document still compiles though. But you're right, the text is not superscripted.

"sub",
"em",
"strong",
{ ["div"] = "hbox" },
Copy link
Owner

@Omikhleia Omikhleia Nov 16, 2022

Choose a reason for hiding this comment

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

A div cannot be made an hbox (or it won't be properly line broken) -- same for a span actually.

But more generally, Pandoc has lots of extensions regarding HTML in Markdown, e.g. markdown_in_html_blocks which allows mixing HTML and Markdown, if I read that correctly.

I have one more concern which comes to mind: I'd ideally like both the pandocast and markdown packages to have the same minimal set of features. This imply, for any test we write, looking at what the Pandoc AST would contain, to at least ensure reasonable parity, whichever route is taken.

{ ["b"] = "strong" },
{ ["i"] = "em" },
}

package.registerHTMLcommands = function(self)
self:registerCommand("markdown:html:br", function (_, _)
SU.debug("markdown", "warning: manual linebreak (\\cr) inserted")
SILE.call("cr")
end, "HTML <br/> in Markdown")

for _, p in pairs(passthroughs) do
local html_name, sile_name
if type(p) == "table" then
html_name, sile_name = next(p), p[next(p)]
else
html_name, sile_name = p, p
end

self:registerCommand("markdown:html:" .. html_name, function(options, content)
SU.debug("markdown", "info: " .. html_name .. " replaced by \\" .. sile_name)
return utils.createCommand(sile_name, options, content)
end)
end
end

package.documentation = [[\begin{document}
A helper package for Markdown processing, providing HTML support.

It is not intended to be used alone.
\end{document}]]

return package
1 change: 1 addition & 0 deletions packages/markdown/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package._name = "markdown"
function package:_init (_)
base._init(self)
self.class:loadPackage("markdown.commands")
self.class:loadPackage("markdown.html")

-- Extend inputters if needed.
-- Chicken and eggs... This just forces the inputter to be loaded!
Expand Down