[有人可以帮我写一个运行在html页面中所有div上的lua过滤器,提取一个带有“ bibliographie”类的过滤器,然后插入经过处理的书目(index.bib的内容吗?]
我已经尝试过了,但是我离我想去的地方不远。提前非常感谢!
YAML的一部分:
bibliography: index.bib
template.html的一部分:
<div class="bibliographie">
<h2 class="sources-def-bib-title">Bibliographie</h2>
</div>
和我的lua脚本:
function Pandoc(doc)
local hblocks = {}
for i,el in pairs(doc.blocks) do
if (el.t == "Div" and el.classes[1] == "bibliographie") then
table.insert(meta.bibliography, value)
end
end
return pandoc.Pandoc(hblocks, doc.meta)
end
编辑
我们正在开发一个R包,这是我们使用的pandoc_args:
pandoc_args <- c(pandoc_metadata_arg("lang", "fr"), pandoc_args)
# use the non-breaking space pandoc lua filter
pandoc_args <- c(nbsp_filter_pandoc_args(), pandoc_args)
# hyphenations
pandoc_args <- c(pandoc_metadata_arg("hyphenopoly"), pandoc_args)
逐步看,我们首先要通过过滤所有div元素来提取div内容;为此可以使用Div
过滤器功能,将内容存储在局部变量中。然后,我们需要将提取的内容添加到元数据中; Lua过滤器可以使用Meta
函数仅访问和修改metdata。如果未给出明确的顺序,pandoc将首先过滤块,然后过滤元数据,这正是我们想要的。
-- This will contain the contents of the div with id "bibliographie".
local bibliographie
function Div (div)
if div.classes[1] == 'bibliographie' then
bibliographie = div.content
return {} -- Removes the item from the document.
-- Drop these lines to keep the div.
end
end
function Meta (meta)
meta.bibliographie = bibliographie
return meta
end
official docs包含所有详细信息,如果需要。