File: includes.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 (21 lines) | stat: -rwxr-xr-x 628 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3

"""
Pandoc filter to process code blocks with class "include" and
replace their content with the included file
"""

from pandocfilters import toJSONFilter


def code_include(key, value, format, meta):
    if key == 'CodeBlock':
        [[ident, classes, namevals], code] = value
        for nameval in namevals:
            if 'include' in nameval:
                with open(nameval[1], 'rb') as content_file:
                    content = unicode(content_file.read())
                return {'CodeBlock': [[ident, classes, namevals], content]}

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