Created
October 22, 2017 02:56
-
-
Save j9ac9k/0ef11987585c55788dadc11ae747e95b to your computer and use it in GitHub Desktop.
pandoc filter to convert gitlab flavor markdown math to pandoc compatible markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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