What can I control with YAML header options in pandoc?

帅比萌擦擦* 提交于 2019-11-28 03:34:51

Actually, it is all contained in Pandoc's MANUAL. Specifically:

Templates may contain variables.

For example in your HTML template, you could write:

<title>$title$</title>

These template variables can be set with the --variable KEY[=VAL] option.

However, they are also set from the document metadata, which in turn can be set either by using:

The --variable options inserts strings verbatim into the template, while --metadata escapes strings. Strings in YAML metadata (also when using --metadata-file) are interpreted as markdown, which you can circumvent by using pandoc markdown's generic raw attributes. For example for HTML output:

`<script>alert()</script>`{=html}

See this table for a schematic of --variable vs --metadata vs YAML metadata.

To answer your question: the template determines what fields in the YAML metadata block have an effect. To view, for example, the latex template, use:

$ pandoc -D latex

To see some variables that are set automatically by pandoc, see the Manual. Finally, other behaviours of pandoc (such as markdown extensions, etc) can only be set as command-line options (except when using a wrapper script).

It is a rather long list that you can browse by running man pandoc in the command line and navigating to "Variables set by pandoc" section under "TEMPLATES."

The top of the list includes the following among many other options:

Variables set by pandoc
   Some variables are set automatically by pandoc.  These vary somewhat depending  on  the
   output format, but include metadata fields as well as the following:

   title, author, date
          allow identification of basic aspects of the document.  Included in PDF metadata
          through LaTeX and ConTeXt.  These can be set through a pandoc title block, which
          allows for multiple authors, or through a YAML metadata block:

                 ---
                 author:
                 - Aristotle
                 - Peter Abelard
                 ...

   subtitle
          document subtitle; also used as subject in PDF metadata

   abstract
          document summary, included in LaTeX, ConTeXt, AsciiDoc, and Word docx

   keywords
          list  of  keywords  to  be  included in HTML, PDF, and AsciiDoc metadata; may be
          repeated as for author, above

   header-includes
          contents specified by -H/--include-in-header (may have multiple values)

   toc    non-null value if --toc/--table-of-contents was specified

   toc-title
          title of table of contents (works only with EPUB and docx)

   include-before
          contents specified by -B/--include-before-body (may have multiple values)

   include-after
          contents specified by -A/--include-after-body (may have multiple values)

   body   body of document

```

You can see the documentation of pandoc for a clue: http://pandoc.org/getting-started.html

But to know exactly where it will be used you can look for templates sources of pandoc: https://github.com/jgm/pandoc-templates

For example, for the html5 output the file is: https://github.com/jgm/pandoc-templates/blob/master/default.html5

Here's an section of the code:

<title>$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$</title>

As you can see it has title-prefix and pagetitle.

You can look the documentation, but the best solution is to look for the source code of the version you are using.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!