获取pandoc模板中的第一个作者(Rmarkdown)



我目前正在为Rmarkdown创建自己的pandoc模板(输出html(。我希望我的报告显示一个页脚,其中包含标题和第一作者的姓名

阅读pandoc手册,我发现可以使用管道来获取数组的第一个元素(var/first(。所以有了标题:

title: "My Report"
author:
- "Jane Doe"
- "John Doe"

我尝试在模板中做以下操作:

<div class="footer">
<div class="footer-content">
<div class="footer-title">
<h3>$title$</h3>
</div>
<div class="footer-author">
<h3>$author/first$</h3>
</div>
</div>
</div>

然后我在作者行中得到了一个错误:

"template" (line 96, column 24):
unexpected "/"
expecting "." or "$"

请注意,rmarkdown使用的pandoc版本是2.3.1

有什么不同的方法可以做到这一点吗?

您可以编写一个小型Lua过滤器来获得第一作者:

function Meta (meta)
local firstauthor = meta.author.t == 'MetaList'
and meta.author[1]
or meta.author
meta.firstauthor = firstauthor
return meta
end

然后可以在模板中使用$firstauthor$。有关Lua过滤器以及如何使用它们的简短讨论,请参阅此处。

最新更新