pandocfilters

1.5.1 · active · verified Sat Mar 28

pandocfilters is a Python library that provides utilities for writing Pandoc filters. These filters manipulate Pandoc's Abstract Syntax Tree (AST) in its JSON representation between the reader (parser) and writer (output format). It is currently at version 1.5.1 and sees an active, though irregular, release cadence focused on maintenance and compatibility with Pandoc versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a simple Pandoc filter that converts all regular string elements ('Str') in the document's Abstract Syntax Tree (AST) to uppercase. Save this code as a Python file (e.g., `caps_filter.py`), make it executable, and then run Pandoc with the `--filter` option pointing to your script.

#!/usr/bin/env python
"""
Pandoc filter to convert all regular text ('Str' elements) to uppercase.
Run with: pandoc input.md --filter ./caps_filter.py -o output.html
"""

from pandocfilters import toJSONFilter, Str

def caps(key, value, format, meta):
    if key == 'Str':
        return Str(value.upper())

if __name__ == "__main__":
    toJSONFilter(caps)

view raw JSON →