gpt4 book ai didi

pandoc - 使用 pandoc 和 YAML header 列出标签

转载 作者:行者123 更新时间:2023-12-01 15:56:16 25 4
gpt4 key购买 nike

我正在用 Markdown 编写(带有 YAML header )并尝试使用 pandoc 转换为 HTML。我的 YAML header 有一个“标签”字段,它是一个列表,如以下示例所示:

---
title: Title
tags: [one, two]
...

Text.

在最终结果中,我想很好地显示标签,例如逗号分隔的列表。但是,在我的 pandoc 模板中,变量 $tags$ 只包含第一个标签。执行类似 $for(tags)$$tags$, $endfor$ 的操作将生成所有标签,但结尾的逗号和空格是个问题。如何在最终 HTML 中将标签列表显示为 one, two 而不是 oneone, two,

最佳答案

我在 Templates 下的官方文档中错过了这个:

When variables can have multiple values (for example, author in a multi-author document), you can use the $for$ keyword:

$for(author)$
<meta name="author" content="$author$" />
$endfor$

You can optionally specify a separator to be used between consecutive items:

$for(author)$$author$$sep$, $endfor$

所以在我的例子中,我会在模板中执行 $for(tags)$$tags$$sep$, $endfor$

关于pandoc - 使用 pandoc 和 YAML header 列出标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25559469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com