Pandoc: YAML Metadata Template

I use pandoc to generate index.html with YAML metadata. I know the iteration of associative arrays from the pandoc template:

Yaml

- Author: Mastropiero - Author: Gunter Fraggen 

TEMPLATE

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

But ... How to repeat lists without a key ?

YAML :

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

TEMPLATE

 $for(author)$ ... // how works? $endfor$ 
+6
source share
1 answer

As your template shows, inside the loop pandoc creates a local variable with the same name as the array ('author' in your case). To iterate over an internal list, simply use the same "for" mechanism for the internal variable.

So you should use

TEMPLATE

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

You can also use $ sep $ to specify a separator to use between list items.

Please note that if the internal list contains items with different values ​​(not just the list), you should use a dictionary list.

Yaml

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

TEMPLATE

 $for(author)$ $author.name$ wrote $author.book$ $endfor$ 
+12
source

Source: https://habr.com/ru/post/977019/


All Articles