about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2020-12-02 20:13:51 -0500
committerZach DeCook <zachdecook@librem.one>2020-12-02 20:17:09 -0500
commita56329ccd6c7476281ced948ea143d04647bca88 (patch)
tree98d9921988e2f232ecd5df5b2fd600cd9c1b28ae
downloadthml2gmi-a56329ccd6c7476281ced948ea143d04647bca88.tar.gz
Parse div1 div2 div3 as headings
-rwxr-xr-xthml2gmi.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/thml2gmi.py b/thml2gmi.py
new file mode 100755
index 0000000..24bc18a
--- /dev/null
+++ b/thml2gmi.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+import sys
+import xml.etree.ElementTree as ET
+
+def main(argv):
+    root = ET.parse(argv[1]).getroot()
+    head = root.find('ThML.head')
+    body = root.find('ThML.body')
+    for thing in list(body):
+        parseSomething(thing)
+
+def parseSomething(thing):
+    if(len(thing.tag) == 4 and thing.tag[:3] == 'div'):
+        parseDiv(thing)
+
+def parseDiv(div):
+    indentLevel = int(div.tag[3:])
+    title = div.get('title')
+    print('#' * indentLevel + ' ' + title)
+    for child in list(div):
+        parseSomething(child)
+
+if __name__ == '__main__':
+    main(sys.argv)