Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
""" |
| 4 |
Pandoc filter to exact python code blocks and write each snippet out. |
| 5 |
""" |
| 6 |
|
| 7 |
from pandocfilters import toJSONFilter, Str |
| 8 |
|
| 9 |
n = 0 |
| 10 |
|
| 11 |
|
| 12 |
def caps(key, value, format, meta): |
| 13 |
global n |
| 14 |
if key == "CodeBlock": |
| 15 |
py_types = value[0][1][0] |
| 16 |
if py_types.encode("ascii") == "python": |
| 17 |
code_block = value[-1] |
| 18 |
# eval(code_block) |
| 19 |
with open("readme-snippet-{n}.py".format(n=n), 'a') as f: |
| 20 |
f.write("# example {k}-{n}\n".format(k=key, n=n)) |
| 21 |
f.write("{v}\n".format(v=code_block)) |
| 22 |
|
| 23 |
n += 1 |
| 24 |
|
| 25 |
|
| 26 |
if __name__ == "__main__": |
| 27 |
toJSONFilter(caps) |