From f82b41b820f559890c7f5132e21e8d746a8d1b1d Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Wed, 3 Jun 2026 06:38:10 -0400 Subject: Handle \ref tag --- usfm2gmi.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'usfm2gmi.py') diff --git a/usfm2gmi.py b/usfm2gmi.py index 665706a..ce283fe 100755 --- a/usfm2gmi.py +++ b/usfm2gmi.py @@ -35,10 +35,12 @@ def superscript(word): def convert(line, printStrongs=False): """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('\\+nd*','\\+nd* ').replace('\\f*','\\f* ').replace('\\wj*','\\wj* ').replace('\\w*',' \\w* ').replace('\\+w*', '\\+w* ').split() + split = line.replace('\\', ' \\').replace('\\nd*','\\nd* ').replace('\\+nd*','\\+nd* ').replace('\\f*','\\f* ').replace('\\wj*','\\wj* ').replace('\\w*',' \\w* ').replace('\\+w*', '\\+w* ').replace('\\ref*', '\\ref* ').split() out = '' nd = False superS = False + ref = False + yesprint = True if len(split) == 0: return out elif split[0] in ['\\mt1','\\mt','\\ms','\\h']: @@ -106,6 +108,17 @@ def convert(line, printStrongs=False): continue elif word == '\\x*': out += ')' + # https://docs.usfm.bible/usfm/3.1.1/char/features/ref.html + elif word == '\\ref': + ref = True + elif word == '\\ref*': + ref = False + yesprint = True + elif ref and '|' in word: + spl = word.split('|') + out += spl[0] + # Everything after the pipe is the link + yesprint = False # TODO: support Endnotes (\fe and \fe*) elif word in ['\\ft']: continue # TODO: fancy formatting of more types @@ -139,7 +152,7 @@ def convert(line, printStrongs=False): out += smallcaps(word) + ' ' if superS: out += superscript(word) + ' ' - else: + elif yesprint: out += word + ' ' return out -- cgit 1.4.1