summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <abobov@gmail.com>2016-12-02 09:09:39 +0500
committerAnton Bobov <abobov@gmail.com>2016-12-02 09:09:39 +0500
commit03be9e0536963e3ff4a628ed78347b9569b52ee3 (patch)
treef13a9770d900d728788a6f3874f903fa766e45b6
parent0a6657b3a4b8153d1c42302486a8a61800fde9b1 (diff)
Add pandoc include filter.
-rwxr-xr-xpandoc-filter-includes.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/pandoc-filter-includes.py b/pandoc-filter-includes.py
new file mode 100755
index 0000000..d9b5244
--- /dev/null
+++ b/pandoc-filter-includes.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+"""
+Pandoc filter to process code blocks with class "include" and
+replace their content with the included file
+
+from: https://github.com/simonlau/pandocfilters
+"""
+
+from pandocfilters import toJSONFilter, CodeBlock
+
+
+def code_include(key, value, format, meta):
+ if key == 'CodeBlock':
+ [[ident, classes, namevals], code] = value
+ for nameval in namevals:
+ if nameval[0] == 'include':
+ with open(nameval[1], 'rb') as content_file:
+ content = content_file.read()
+ content.decode('utf-8')
+ return CodeBlock([ident, classes, namevals], content)
+
+if __name__ == "__main__":
+ toJSONFilter(code_include)