gpt4 book ai didi

arrays - Pandoc:具有YAML元数据的模板

转载 作者:行者123 更新时间:2023-12-04 13:22:56 25 4
gpt4 key购买 nike

我使用pandoc使用YAML元数据生成index.html。我知道从pandoc模板迭代关联数组:

YAML :

- Author: Mastropiero
- Author: Gunter Fraggen

TEMPLATE :
$for(author)$
$author$
$endfor$

但是...如何在没有 key 的情况下迭代列表 呢?

YAML :
- Author:
- [Value1, Value2]
- [Value1B, Value2B]

TEMPLATE :
$for(author)$
... // how works?
$endfor$

最佳答案

如您的模板所示,pandoc在循环中创建一个与数组同名的本地变量(在本例中为'author')。因此,要遍历内部列表,只需对内部变量使用相同的“for”机制。

因此,您应该使用

TEMPLATE

$for(author)$
$for(author)$
$author$
$endfor$
$endfor

您还可以使用$ sep $指定要在列表元素之间使用的分隔符。

请注意,如果内部列表包含具有不同含义的元素(而不只是列表),则应使用字典列表。

YAML
Author:
- {name: Iain Banks, book: The Algebraist}
- {name: Isaac Asimov, book: Foundation}

TEMPLATE
$for(author)$
$author.name$ wrote $author.book$
$endfor$

关于arrays - Pandoc:具有YAML元数据的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26483499/

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