Package: scholdocfilters
A Python module for writing Scholdoc filters, forking off the
original pandoc filters. Scholdoc filters are pipes that read a JSON
serialization of the Scholdoc AST from stdin, transform it in some
way, and write it to stdout. They can be used with Scholdoc (>= 0.1.3)
either using pipes::scholdoc -t json | ./caps.py | scholdoc -f jsonor using the--filter(or-F) command-line option::scholdoc --filter ./caps.pyScholdocfilters is just jgm’s pandocfilters with element types
adapted to the slightly richer Scholdoc AST. For more usage
information, see John MacFarlane’s original pandoc documentation
under--filterandthe tutorial on writing filters.To install:python setup.py installThescholdocfiltersmodule exports the following functions:walk(x, action, format, meta)Walk a tree, applying an action to every object.
Returns a modified tree.toJSONFilter(action)Converts an action into a filter that reads a JSON-formatted
Scholdoc document from stdin, transforms it by walking the tree
with the action, and returns a new JSON-formatted Scholdoc document
to stdout. The argument is a function action(key, value, format,
meta), where key is the type of the Scholdoc object (e.g. ‘Str’,
‘Para’), value is the contents of the object (e.g. a string for
‘Str’, a list of inline elements for ‘Para’), format is the target
output format (which will be taken for the first command line
argument if present), and meta is the document’s metadata. If the
function returns None, the object to which it applies will remain
unchanged. If it returns an object, the object will be replaced. If
it returns a list, the list will be spliced in to the list to which
the target object belongs. (So, returning an empty list deletes the
object.)stringify(x)Walks the treexand returns concatenated string content,
leaving out all formatting.attributes(attrs)Returns an attribute list, constructed from the
dictionaryattrs.Most users will only needtoJSONFilter.  Here is a simple example
of its use::#!/usr/bin/env python

"""
Scholdoc filter to convert all regular text to uppercase.
Code, link URLs, etc. are not affected.
"""

from scholdocfilters import toJSONFilter, Str

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

if __name__ == "__main__":
  toJSONFilter(caps)ExamplesNOTE: These example are written forpandocfilters. As such, some examples
are not working due to an incompatible AST between Scholdoc and Pandoc. This
will be remedied ASAP.The examples subdirectory in the source repository contains the
following filters. These filters should provide a useful starting
point for developing your own scholdocfilters.abc.pyPandoc filter to process code blocks with classabccontaining ABC
notation into images. Assumes that abcm2ps and ImageMagick’s convert
are in the path. Images are put in the abc-images directory.caps.pyPandoc filter to convert all regular text to uppercase. Code, link
URLs, etc. are not affected.comments.pyPandoc filter that causes everything between<!--BEGIN COMMENT-->and<!--END COMMENT-->to be ignored.
The comment lines must appear on lines by themselves, with blank
lines surroundingdeemph.pyPandoc filter that causes emphasized text to be displayed in ALL
CAPS.deflists.pyPandoc filter to convert definition lists to bullet lists with the
defined terms in strong emphasis (for compatibility with standard
markdown).graphviz.pyPandoc filter to process code blocks with classgraphvizinto
graphviz-generated images.metavars.pyPandoc filter to allow interpolation of metadata fields into a
document.%{fields}will be replaced by the field’s value, assuming
it is of the typeMetaInlinesorMetaString.myemph.pyPandoc filter that causes emphasis to be rendered using the custom
macro\myemph{...}rather than\emph{...}in latex. Other output
formats are unaffected.theorem.pyPandoc filter to convert divs withclass="theorem"to LaTeX theorem
environments in LaTeX output, and to numbered theorems in HTML
output.tikz.pyPandoc filter to process raw latex tikz environments into images.
Assumes that pdflatex is in the path, and that the standalone
package is available. Also assumes that ImageMagick’s convert is in
the path. Images are put in thetikz-imagesdirectory.