about summary refs log tree commit diff
path: root/usx2gmi.py
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2021-02-27 22:57:04 -0500
committerZach DeCook <zachdecook@librem.one>2021-02-27 22:57:04 -0500
commit5d0d4ca4f1b3164b977f1645b44b65fe76ee192d (patch)
tree0ff5474b2fea5324e2d184e9a7400651e80f297e /usx2gmi.py
parent794d2313ecd1f9fdd2f0981b957adbc04a2cf77e (diff)
downloadusfm2gmi-5d0d4ca4f1b3164b977f1645b44b65fe76ee192d.tar.gz
usx2gmi: Start this script
Diffstat (limited to 'usx2gmi.py')
-rwxr-xr-xusx2gmi.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/usx2gmi.py b/usx2gmi.py
new file mode 100755
index 0000000..cc7709d
--- /dev/null
+++ b/usx2gmi.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+"""Convert a usx file into gemtext"""
+__author__ = "Zach DeCook"
+__email__ = "zachdecook@librem.one"
+__copyright__ = "Copyright (C) 2021 Zach DeCook"
+__license__ = "AGPL"
+__version__ = "3"
+
+import sys
+import xml.etree.ElementTree as ET
+
+def printf(string):
+    print(string,end='')
+
+def main(argv):
+    root = ET.parse(argv[1]).getroot()
+    for thing in list(root):
+        printf(convertBlock(thing))
+
+def convertBlock(thing):
+    if thing.tag == 'para':
+        # TODO: use style attribute to affect the prefix.
+        return "\n" + convertInline(thing)
+    return ''
+
+def convertInline(thing):
+    # TODO: Implement this.
+    if thing.text:
+        return thing.text.replace("\n"," ").strip()
+    return ''
+
+if __name__ == '__main__':
+    main(sys.argv)