Lua filter to wrap each paragraph in a custom-style "Paragraph" div, and apply "New paragraph" div for paragraphs after a blockquote or a heading or title (beginning) for Word template export #10124
-
I'm new to writing Lua filters (have zero programming experience), but I managed to write a filter to turn Blockquotes into a custom-style div for a word template I need to use:
This was easy. But now, I want to wrap every paragraph. The way I understand it, I would need to somehow distinguish "Para" elements in the AST that are part of the top-level, but exclude any Para that is nested inside a deeper element. Also (in a second script probably), I would need to test for the conditions of a "New paragraph," and then change the newly made "Paragraph" divs into that. But how can I do that? I am still learning Lua, and I think the solution (at least for the first part) has something to do with "walking the AST?" Any tips would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Use the local function Blocks (blocks)
for i, block in ipairs(blocks) do
if block.t == "Para" then
blocks[i] = pandoc.Div(block.content, {...})
end
end
return blocks
end |
Beta Was this translation helpful? Give feedback.
Use the
Blocks
filter and iterate over the top level blocks yourself instead of letting Pandoc throwPara
blocks to your filter willy-nilly. Change them to what you want them to be in place, something like this: