Skip to content

Commit

Permalink
chore(classes): Redo markdown class with Penlight class model
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed May 10, 2022
1 parent d115cd1 commit f1b8a57
Showing 1 changed file with 42 additions and 32 deletions.
74 changes: 42 additions & 32 deletions classes/markdown.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
-- You will need my lunamark fork from https://github.com/simoncozens/lunamark
-- for the AST writer.

local book = require("classes.book")
local markdown = pl.class(book)
markdown._name = "markdown"

SILE.inputs.markdown = {
order = 2,
appropriate = function (fn, _)
Expand All @@ -18,47 +22,53 @@ SILE.inputs.markdown = {
end
}

SILE.require("packages/url")
SILE.require("packages/image")
function markdown:_init (options)
if self._legacy and not self._deprecated then return self:_deprecator(book) end
book._init(self, options)
self:loadPackage("url")
self:loadPackage("image")
-- Avoid calling this (yet) if we're the parent of some child class
if self._name == "markdown" then self:post_init() end
return self
end

local book = SILE.require("book", "classes")
local markdown = book { id = "markdown" }
function markdown:registerCommands ()

function markdown:init ()
return book.init(self)
end
book.registerCommands(self)

SILE.registerCommand("sect1", function (options, content)
SILE.call("chapter", options, content)
end)
SILE.registerCommand("sect1", function (options, content)
SILE.call("chapter", options, content)
end)

SILE.registerCommand("sect2", function (options, content)
SILE.call("section", options, content)
end)
SILE.registerCommand("sect2", function (options, content)
SILE.call("section", options, content)
end)

SILE.registerCommand("sect3", function (options, content)
SILE.call("subsection", options, content)
end)
SILE.registerCommand("sect3", function (options, content)
SILE.call("subsection", options, content)
end)

SILE.registerCommand("emphasis", function (options, content)
SILE.call("em", options, content)
end)
SILE.registerCommand("emphasis", function (options, content)
SILE.call("em", options, content)
end)

SILE.registerCommand("paragraph", function (_, content)
SILE.process(content)
SILE.call("par")
end)
SILE.registerCommand("paragraph", function (_, content)
SILE.process(content)
SILE.call("par")
end)

SILE.registerCommand("bulletlist", function (_, content)
SILE.process(content)
end)
SILE.registerCommand("bulletlist", function (_, content)
SILE.process(content)
end)

SILE.registerCommand("link", function (_, content)
SILE.call("verbatim:font", {}, content)
end)
SILE.registerCommand("link", function (_, content)
SILE.call("verbatim:font", {}, content)
end)

SILE.registerCommand("image", function (_, content)
SILE.call("img", {src=content.src})
end)
SILE.registerCommand("image", function (_, content)
SILE.call("img", {src=content.src})
end)

end

return markdown

0 comments on commit f1b8a57

Please sign in to comment.