/usr/lib/grass72/tools/g.html2man.py is in grass-dev 7.2.0-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #!/usr/bin/env python
import sys
import re
from html import HTMLParser, HTMLParseError
from groff import Formatter
from StringIO import StringIO
entities = {
'nbsp': " ",
'bull': "*"
}
# Remove ToC
def fix(content):
if isinstance(content, tuple):
tag, attrs, body = content
if tag == 'div' and ('class', 'toc') in attrs:
return None
else:
return (tag, attrs, fix(body))
elif isinstance(content, list):
return [fixed
for item in content
for fixed in [fix(item)]
if fixed is not None]
else:
return content
def main():
# parse HTML
infile = sys.argv[1]
inf = file(infile)
p = HTMLParser(entities)
for n, line in enumerate(inf):
try:
p.feed(line)
except HTMLParseError as err:
sys.stderr.write(
'%s:%d:%d: Parse error: %s\n' %
(infile, err.lineno, err.offset, err.msg))
sys.exit(1)
except Exception as err:
sys.stderr.write(
'%s:%d:0: Error (%s): %s\n' %
(infile, n + 1, repr(err), line))
sys.exit(1)
p.close()
inf.close()
# generate groff
sf = StringIO()
f = Formatter(infile, sf)
f.pp(fix(p.data))
s = sf.getvalue()
sf.close()
# strip excess whitespace
blank_re = re.compile("[ \t\n]*\n([ \t]*\n)*")
s = blank_re.sub('\n', s)
s = s.lstrip()
# write groff
outf = file(sys.argv[2], 'w')
outf.write(s)
outf.close()
if __name__ == "__main__":
main()
|