Pandoc: Template with YAML metadata

后端 未结 1 1290
醉话见心
醉话见心 2021-01-05 07:27

I use pandoc for generate index.html with YAML metadata. I know iterate associative arrays from pandoc template:

YAML:

- Author: Mas         


        
1条回答
  •  清酒与你
    2021-01-05 07:36

    As your template shows, within a loop pandoc makes a local variable with the same name as the array ('author' in your case). So to iterate through the inner list, simply use the same 'for' mechanism on the inner variable.

    Thus, you should use

    TEMPLATE

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

    You can also use $sep$ to specify a separator to use between the elements of the list.

    Note that if the inner list has elements with different meanings (rather than just a list) then you should use a list of dictionaries.

    YAML

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

    TEMPLATE

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

    0 讨论(0)
提交回复
热议问题