Skip to content

Commit

Permalink
Format with black
Browse files Browse the repository at this point in the history
  • Loading branch information
megabyde committed Nov 22, 2022
1 parent 03c7de3 commit a9efb49
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions pandoc-minted.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit a9efb49

Please sign in to comment.