-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.py
51 lines (42 loc) · 1.46 KB
/
debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2016 Sergio Correia <[email protected]>
#
# SPDX-License-Identifier: BSD-3-Clause
"""
This is part of the [MoVeDo](https://github.com/movedo) project.
Pretty print contents of the filters' input (both sys.argv and the JSON)
Usage example:
$ pandoc -f markdown -t markdown --markdown-headings=atx \
--filter debug.py \
-o output.md \
input.md
"""
import sys
import json
import pprint
import pkg_resources
import panflute as pf
def action(elem, doc):
if isinstance(elem, pf.Doc):
version = pkg_resources.get_distribution("panflute").version
json_serializer = lambda elem: elem.to_json()
raw = json.dumps(elem, default=json_serializer)
raw = json.loads(raw)
raw = json.dumps(raw, check_circular=False,
indent=4, separators=(',', ': '))
disclaimer = pf.Para(pf.Emph(pf.Str('Note: sort order not preserved')))
elem.content = [
pf.Header(pf.Str('Python version:'), level=2),
pf.Para(pf.Str(sys.version)),
pf.Header(pf.Str('Panflute version:'), level=2),
pf.Para(pf.Str(version)),
pf.Header(pf.Str('sys.argv:'), level=2),
pf.Plain(pf.Str(str(sys.argv))),
pf.Header(pf.Str('JSON Input:'), level=2),
disclaimer,
pf.CodeBlock(raw)
]
def main(doc=None):
return pf.run_filter(action, doc=doc)
if __name__ == '__main__':
main()