Theological Markup Language to gemtext converter
Parse div1 div2 div3 as headings
Zach DeCook 2020-12-02
commit a56329c
-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)