[英]Pandoc Lua filter: How can I check in function Str if argument comes from a title (of a chapter or section)
actually, i do some filtering for the markdown to LaTeX transformation.实际上,我为 markdown 到 LaTeX 转换做了一些过滤。 I use lua filters for this.我为此使用 lua 过滤器。 Now i'd need to do something like this:现在我需要做这样的事情:
function Str (el)
if is_in_a_title(el) then
-- do this
else
-- do that
end
end
meaning that inside Str i want to check if the argument belongs to a chapter/section title.这意味着在 Str 中我想检查参数是否属于章节/章节标题。 Is there any way to do this?有没有办法做到这一点?
Re-posting what I wrote on the mailing list:重新发布我在邮件列表上写的内容:
This is best done by running sub-filters:这最好通过运行子过滤器来完成:
local header_filter = {
Str = function (el)
-- do this
end
}
function Header (h)
return pandoc.util.walk_block(h, header_filter)
end
The header_filter
is just like a normal Lua filter. header_filter
就像普通的 Lua 过滤器一样。 The walk_block
function applies that filter to all elements below the Header, and those elements only. walk_block
function 将该过滤器应用于 Header 下方的所有元素,并且仅适用于这些元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.