【问题标题】:Getting the first author in a pandoc template (Rmarkdown)在 pandoc 模板中获取第一作者 (Rmarkdown)
【发布时间】:2020-07-24 07:53:25
【问题描述】:

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

阅读pandoc manual,我看到可以使用管道获取数组的第一个元素(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

有没有其他方法可以做到这一点?

【问题讨论】:

  • 该模板语法是在更高版本的 pandoc 中引入的....所以尝试更新..pandoc.org/installing.html
  • 此功能的最低版本是 pandoc 2.10。

标签: r-markdown pandoc


【解决方案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 过滤器以及如何使用它们的简要讨论,请参阅 here

【讨论】:

    猜你喜欢
    • 2018-05-20
    • 1970-01-01
    • 2011-04-01
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多