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)
|