浏览代码

Remove ToC (added in https://trac.osgeo.org/grass/changeset/59673)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@59825 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 11 年之前
父节点
当前提交
2796da96ad
共有 1 个文件被更改,包括 17 次插入1 次删除
  1. 17 1
      tools/g.html2man/g.html2man.py

+ 17 - 1
tools/g.html2man/g.html2man.py

@@ -10,6 +10,22 @@ entities = {
     '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]
@@ -30,7 +46,7 @@ def main():
     # generate groff
     sf = StringIO()
     f = Formatter(infile, sf)
-    f.pp(p.data)
+    f.pp(fix(p.data))
     s = sf.getvalue()
     sf.close()