-
This seems like it should be easy. Given the input: # Top Level 1
Text
## Sub heading
Text
## Sub heading
Text The command # Top Level 1
Text
## Sub heading
Text
## Sub heading
Text And I would like to produce nearly the same thing, but with two blank lines above each section heading: # Top Level 1
Text
## Sub heading
Text
## Sub heading
Text Examples make me think this should be easy, with a custom Lua writer something like: function Writer(doc, opts)
local filter = {
Header = function(header)
-- something with pandoc.layout.blanklines(2)
return header
end,
}
return pandoc.write(doc:walk(filter), "commonmark_x", opts)
end
Template = pandoc.template.default "commonmark_x" But I'm not quite figuring out how to make it click. The filter is dealing with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 14 replies
-
Progress: Writer = pandoc.scaffolding.Writer
Writer.Block.Header = function (header)
return {
pandoc.layout.blanklines(2),
string.rep("#", header.level) .. ' ',
Writer.Inlines(header.content)
}
end
Writer.Block.Para = function (para)
return {Writer.Inlines(para.content), pandoc.layout.blankline}
end
Writer.Inline.Str = function (str)
return str.text
end
Writer.Inline.Space = function (space)
return pandoc.layout.space
end This works well enough for the example text. But it would require defining functions for all AST nodes. In an OO paradigm, I would subclass a "CommonMarkWriter" visitor, then override the "Header" method (while calling the original method after adding blank lines). I'm not sure how to proceed with the lua API here. |
Beta Was this translation helpful? Give feedback.
OK, I've pushed a commit that should allow these initial/final newlines in markdown raw blocks to be preserved.