Lua 过滤器用于插入自定义书目



有人可以帮我编写一个lua过滤器,该过滤器在html页面中的所有div上运行,提取带有类"bibliographie"的过滤器并插入处理后的参考书目(index.bib的内容(?

我已经试过了,但我离我想去的地方还很远。 提前非常感谢!

亚姆尔的一部分:

bibliography: index.bib

模板的一部分.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

这假设pandoc-citeproc已经运行,所以Lua过滤器必须在pandoc-citeproc过滤器之后给出:--filter pandoc-citeproc --lua-filter bibliographie-to-meta.lua

如果需要,官方文档包含所有详细信息。

最新更新