Man*_*anz 6 arrays templates yaml pandoc
我使用pandoc生成带有YAML元数据的index.html.我知道pandoc模板中的迭代关联数组:
YAML:
- Author: Mastropiero
- Author: Gunter Fraggen
Run Code Online (Sandbox Code Playgroud)
模板:
$for(author)$
$author$
$endfor$
Run Code Online (Sandbox Code Playgroud)
但是......如何在没有密钥的情况下迭代列表?
YAML:
- Author:
- [Value1, Value2]
- [Value1B, Value2B]
Run Code Online (Sandbox Code Playgroud)
模板:
$for(author)$
... // how works?
$endfor$
Run Code Online (Sandbox Code Playgroud)
小智 15
正如您的模板所示,在一个循环中,pandoc会生成一个与数组同名的局部变量(在您的情况下为"author").因此,要迭代内部列表,只需在内部变量上使用相同的"for"机制.
因此,你应该使用
模板
$for(author)$
$for(author)$
$author$
$endfor$
$endfor
Run Code Online (Sandbox Code Playgroud)
您还可以使用$ sep $指定要在列表元素之间使用的分隔符.
请注意,如果内部列表具有不同含义的元素(而不仅仅是列表),那么您应该使用字典列表.
YAML
Author:
- {name: Iain Banks, book: The Algebraist}
- {name: Isaac Asimov, book: Foundation}
Run Code Online (Sandbox Code Playgroud)
模板
$for(author)$
$author.name$ wrote $author.book$
$endfor$
Run Code Online (Sandbox Code Playgroud)