File: gitlab_markdown.py

package info (click to toggle)
python-pandocfilters 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 376 kB
  • sloc: python: 802; makefile: 26
file content (25 lines) | stat: -rwxr-xr-x 728 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3

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 len(classes) > 0 and classes[0] == "math":
            fmt = {'t': 'DisplayMath',
                   'c': []}
            return Para([Math(fmt, code)])

    elif key == "Math":
        [fmt, code] = value
        if isinstance(fmt, dict) and fmt['t'] == "InlineMath":
            # if fmt['t'] == "InlineMath":
            return Math(fmt, code.strip('`'))


if __name__ == "__main__":
    toJSONFilter(gitlab_markdown)