git.iko.soy/typeable/pandoc
on 0b5156c help sign in
30 lines 696 B history raw
1#!/usr/bin/env python
2from pandoc import toJSONFilter
3import re
5"""
6Pandoc filter that causes everything between
7'<!-- BEGIN COMMENT -->' and '<!-- END COMMENT -->'
8to be ignored. The comment lines must appear on
9lines by themselves, with blank lines surrounding
10them.
11"""
13incomment = False
15def comment(k,v,fmt):
16 global incomment
17 if k == 'RawBlock':
18 fmt, s = v
19 if fmt == "html":
20 if re.search("<!-- BEGIN COMMENT -->", s):
21 incomment = True
22 return []
23 elif re.search("<!-- END COMMENT -->", s):
24 incomment = False
25 return []
26 if incomment:
27 return [] # suppress anything in a comment
29if __name__ == "__main__":
30 toJSONFilter(comment)