Skip to content

Instantly share code, notes, and snippets.

@j9ac9k
Created October 22, 2017 02:56
Show Gist options
  • Save j9ac9k/0ef11987585c55788dadc11ae747e95b to your computer and use it in GitHub Desktop.
Save j9ac9k/0ef11987585c55788dadc11ae747e95b to your computer and use it in GitHub Desktop.
pandoc filter to convert gitlab flavor markdown math to pandoc compatible markdown
from pandocfilters import toJSONFilter, Math, Para
"""
Pandoc filter to convert gitlab flavored markdown to pandoc flavored markdown
"""
def gitlab_markdown(key, value, format, meta):
if key == "CodeBlock":
[[identification, classes, keyvals], code] = value
if classes[0] == "math":
fmt = {'t': 'DisplayMath',
'c': []}
return Para([Math(fmt, code)])
elif key == "Math":
[fmt, code] = value
if isinstance(fmt, dict) and 't' in fmt.keys():
if fmt['t'] == "InlineMath":
return Math(fmt, code.strip('`'))
if __name__ == "__main__":
toJSONFilter(gitlab_markdown)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment