equal
deleted
inserted
replaced
|
1 #!/usr/bin/env python |
|
2 """ |
|
3 Insert a raw-file as HTML code block |
|
4 """ |
|
5 |
|
6 import panflute as pf |
|
7 |
|
8 |
|
9 def action(elem, doc): |
|
10 if isinstance(elem, pf.CodeBlock) and 'raw-file' in elem.classes: |
|
11 filepath = elem.text |
|
12 |
|
13 with open(filepath, 'r') as fd: |
|
14 content = fd.read() |
|
15 |
|
16 return pf.RawBlock('<pre>%s</pre>' % content, "html") |
|
17 # elem.text = content |
|
18 |
|
19 def main(doc=None): |
|
20 return pf.run_filter(action, doc=doc) |
|
21 |
|
22 |
|
23 if __name__ == '__main__': |
|
24 main() |