diff --git a/pandoc-minted.py b/pandoc-minted.py index 0564405..5ffc213 100644 --- a/pandoc-minted.py +++ b/pandoc-minted.py @@ -10,41 +10,43 @@ def unpack_code(value): """Unpack the body and language of a pandoc code element.""" [[_, classes, attributes], contents] = value - language = classes[0] if len(classes) > 0 else 'text' - attributes = ', '.join('='.join(x) for x in attributes) + language = classes[0] if len(classes) > 0 else "text" + attributes = ", ".join("=".join(x) for x in attributes) - return {'contents': contents, 'language': language, 'attributes': attributes} + return {"contents": contents, "language": language, "attributes": attributes} def fragile(key, value, format, meta): """Make headers/frames fragile.""" - if format != 'beamer': + if format != "beamer": return - if key == 'Header': + if key == "Header": level, meta, contents = value # Add the attribute - meta[1].append('fragile') + meta[1].append("fragile") return Header(level, meta, contents) def minted(key, value, format, meta): """Use minted for code in LaTeX.""" - if format != 'latex' and format != 'beamer': + if format != "latex" and format != "beamer": return - if key == 'CodeBlock': - template = Template('\\begin{minted}[$attributes]{$language}\n$contents\n\end{minted}') + if key == "CodeBlock": + template = Template( + "\\begin{minted}[$attributes]{$language}\n$contents\n\end{minted}" + ) Element = RawBlock - elif key == 'Code': - template = Template('\\mintinline[$attributes]{$language}{$contents}') + elif key == "Code": + template = Template("\\mintinline[$attributes]{$language}{$contents}") Element = RawInline else: return text = template.substitute(unpack_code(value)) - return Element('latex', text) + return Element("latex", text) -if __name__ == '__main__': +if __name__ == "__main__": toJSONFilters([fragile, minted])