Convert usfm bibles into gemtext (python library/utility)
strongs: output code as superscript
| -rwxr-xr-x | usfm2gmi.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/usfm2gmi.py b/usfm2gmi.py index fb25131..43a8c87 100755 --- a/usfm2gmi.py +++ b/usfm2gmi.py @@ -21,10 +21,21 @@ def smallcaps(word): new += c return new +def superscript(word): + #TODO: also superscript lowercase letters + ss='⁰¹²³⁴⁵⁶⁷⁸⁹:;<=>?@ᴬᴮCᴰᴱFᴳᴴᶦᴶᴷᴸᴹᴺᴼᴾQᴿSᵀᵁⱽᵂ' + new = '' + for c in word: + if c >= '0' and c <= 'W': + new += ss[ord(c)-ord('0')] + else: + new += c + return new + def convert(line): """Convert a string to a list of tuples, each a token""" # TODO: preserve the lack of whitespace before a backslash. - split = line.replace('\\', ' \\').replace('\\nd*','\\nd* ').replace('\\f*','\\f* ').replace('\\wj*','\\wj* ').replace('|strong',' |strong').split() + split = line.replace('\\', ' \\').replace('\\nd*','\\nd* ').replace('\\f*','\\f* ').replace('\\wj*','\\wj* ').replace('\\w*','\\w* ').split() out = '' nd = False if len(split) == 0: @@ -83,10 +94,11 @@ def convert(line): # TODO: support Endnotes (\fe and \fe*) elif word in ['\\ft']: continue # TODO: fancy formatting of more types - elif word == '\\w': - continue - elif '|strong' in word: + elif word in ['\\w','\\w*']: continue + elif '|strong="' in word: + spl = word.split('|') + out += spl[0] + superscript(spl[1][8:-1]) + ' ' else: if nd: out += smallcaps(word) + ' ' |