-
Notifications
You must be signed in to change notification settings - Fork 0
/
pandoc_latex_levelup.py
43 lines (33 loc) · 966 Bytes
/
pandoc_latex_levelup.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
#!/usr/bin/python3
"""
Pandoc filter to level up all headers
"""
import panflute as pf
def prepare(doc):
doc.enable=doc.get_metadata('levelup.enable', default='True')
doc.unnumber_h1=doc.get_metadata('levelup.unnumber_h1',default="True")
def action(elem, doc):
# kill switch
# this is useful when if you're using the filter in a script
# and you want to disable the filter on certain files
if not doc.enable :
return elem
#
# header1 are unnumbered by default
# ALL others are leveled up
#
if type(elem) == pf.Header:
if elem.level == 1 :
if doc.unnumber_h1:
elem.classes=['unnumbered']
else:
elem.level-=1
def finalize(doc):
pass
def main(doc=None):
return pf.run_filter(action,
prepare=prepare,
finalize=finalize,
doc=doc)
if __name__ == "__main__":
main()