Skip to content

Instantly share code, notes, and snippets.

@c-forster
Created May 15, 2015 18:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c-forster/e312205cefa7d87ebad3 to your computer and use it in GitHub Desktop.
Save c-forster/e312205cefa7d87ebad3 to your computer and use it in GitHub Desktop.
pandoc filter to create a div class which removes indentation (also requires unprovided CSS for HTML output to work)
#!/usr/bin/python
from pandocfilters import toJSONFilter, RawInline, Para, Space, walk
def latex(s):
return RawInline('latex', s)
def html(s):
return RawInline('html', s)
def deindentParas(key, value, format, meta):
# If we're here, then we are a child node of
# a noindent 'div.'
if key == 'Para':
if format == 'latex':
return Para([latex('\\noindent')]+ [Space()] + value)
if format == 'html':
return Para([html('<span class="noindent">')] + value + [html('</span>')])
return
def noindent(key, value, format, meta):
# Look at each div.
if key == 'Div':
[[ident, classes, kvs], contents] = value
# If the Div is of the noindent class, we run deindentParas
# on all of its children.
if 'noindent' in classes:
return walk(contents, deindentParas, format, meta)
return
if __name__ == "__main__":
toJSONFilter(noindent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment