Convert usfm bibles into gemtext (python library/utility)
Footnotes: basic support
| -rwxr-xr-x | usfm2gmi.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/usfm2gmi.py b/usfm2gmi.py index 90c18ae..aca2e26 100755 --- a/usfm2gmi.py +++ b/usfm2gmi.py @@ -18,7 +18,7 @@ def smallcaps(word): 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* ').split() + split = line.replace('\\', ' \\').replace('\\nd*','\\nd* ').replace('\\f*','\\f* ').split() out = '' nd = False if len(split) == 0: @@ -53,6 +53,17 @@ def convert(line): nd = True elif word == '\\nd*': nd = False + # Footnotes (https://ubsicap.github.io/usfm/notes_basic/fnotes.html) + elif word == '\\f': + out += '[' + skip = 1 # the next character is the footnote caller + elif word == '\\fr': + skip = 1 # verse reference not necessary for inline fn + elif word == '\\f*': + out += ']' + # TODO: support Endnotes (\fe and \fe*) + elif word in ['\\ft']: + continue # TODO: fancy formatting of more types else: if nd: out += smallcaps(word) + ' ' |