Pandoc

http://pandoc.org/

Table of Contents

Templates reference

A variable is evaluated as true if
  • a string that is not entirely white space
  • a non-empty array where the first value is truthy
  • any number (including zero)
  • any object
  • the boolean true (for YAML meta data)

Define customized meta data on org input howto

If you want to control whether or not to include TOC on the output, You can define a custom meta field named NOTOC as follows:

#+NOTOC: t

Then, you can refer this value in the template like:

<!-- Customized option for not including toc through #+NOTOC -->
$if(notoc)$
$else$
$if(toc)$
<h1>Table of Contents</h1>
$table-of-contents$
$endif$
$endif$
</article>

As a side note, it appears that the customized meta field cannot be a list, only be a string field.

pandocfilters reference

import pandocfilters as pf

# =============================================================================
# Filter functions
# =============================================================================
# Should return one of following:
#   pf.Foo: replace (should be blocks for blocks, inlines for inlines)
#       []: delete current element.
#     None: do nothing
# =============================================================================


def foo(key, value, format, meta):
    pass


def bar(key, value, format, meta):
    pass


if __name__ == '__main__':
    pf.toJSONFilters([foo, bar])

Functions are called against Pandoc objects, defined in Text.Pandoc.Definition.

For example, there is a pandoc object Link, which corresponds to <a> tag. It's defined as Link: Attr [Inline] Target. For this node, the arguments of the filter function is:

key
Link
value
[attr, inline, target], where inline is another python list
format
target output format, like html
meta
meta data like title

Note that format and meta are a kind of global values. They seem not to be changed across the nodes.