首页 > 解决方案 > Pandoc 元数据未出现在默认 HTML 模板中

问题描述

我正在使用 pandoc 将 org 和 markdown 文件转换为 HTML。我想在外部 YAML 文件中设置元数据,例如titlesubtitle和标签,并使用模板显示它们。author但是,除了正常的身体转换之外,我什么都看不到。

我正在使用默认的 HTML 模板。我已经预先运行了连接 YAML 配置的转换:

pandoc -t html -o output.html metadata.yaml input.md

我也尝试包括yaml_metadata_block扩展:

pandoc -t html+yaml_metadata_block -o output.html metadata.yaml input.md

另外,我尝试在命令本身中设置变量:

pandoc -t html -o output.html -V title="my title" input.md

我的 YAML 文件如下所示:

---
title: "my title"
subtitle: "my subtitle"
author: "the author"
...

用 来检查默认的 html 模板pandoc -D html,看起来当titleetc. 被定义时,它会放在一个标题块中:

$if(title)$
<header>
<h1 class="title">$title$</h1>
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
$for(author)$
<p class="author">$author$</p>
$endfor$
$if(date)$
<p class="date">$date$</p>
$endif$
</header>

但在任何情况下,html 文件都只包含从input.md. 我认为这是$body$默认模板中定义的行。

如何让这些字段出现在我的 html 文档中?

标签: htmlyamlpandoc

解决方案


我的天哪,我所缺少的只是-s属性!

从手册页:

-s, --standalone
          Produce output with an appropriate header and footer (e.g.  a standalone HTML, LaTeX, TEI, or RTF file, not a fragment).  This option is set automat‐
          ically for pdf, epub, epub3, fb2, docx, and odt output.

因此,以下命令按预期工作

pandoc -s -t html -o output.html metadata.yaml input.md

推荐阅读