Preserve MEV passage metadata

This commit is contained in:
2026-07-05 21:15:19 -05:00
parent 4fcf5d3bed
commit 457600b93d
3 changed files with 152 additions and 10 deletions
+16 -8
View File
@@ -69,8 +69,8 @@ proc loadBibleIndex(rows, translationName: string): BibleIndex =
if line.strip.len == 0:
continue
let parts = line.split('\t', maxsplit = 6)
if parts.len != 4 and parts.len != 7:
let parts = line.split('\t', maxsplit = 7)
if parts.len != 4 and parts.len != 7 and parts.len != 8:
raise newException(ValueError,
"invalid embedded " & translationName & " row: " & line)
@@ -142,6 +142,18 @@ proc selectedVerses(index: BibleIndex, reference: PassageReference, range: RefRa
discard index.requireVerse(code, chapter, verse)
result[verseKey(code, chapter, verse)] = true
proc shouldSeparateSegments(previous, next: string): bool =
if previous.len == 0 or next.len == 0:
return false
if previous[^1].isSpaceAscii or next[0].isSpaceAscii:
return false
next[0] notin {'.', ',', ';', ':', '?', '!', ')', ']', '}'}
proc appendSameLine(line: var string, content: string) =
if shouldSeparateSegments(line, content):
line.add(" ")
line.add(content)
proc addFormattedSegment(
lines: var seq[string],
segment: BibleSegment,
@@ -159,17 +171,13 @@ proc addFormattedSegment(
let hasPassageLine = lines.len > 1 and lines[^1].len > 0
if segment.breakKind == sbSame and hasPassageLine:
if lines[^1].len > 0 and not lines[^1][^1].isSpaceAscii:
lines[^1].add(" ")
lines[^1].add(content)
lines[^1].appendSameLine(content)
else:
let isMarkerlessParagraphContinuation =
segment.breakKind == sbParagraph and marker.len == 0 and hasPassageLine
if isMarkerlessParagraphContinuation:
if lines[^1].len > 0 and not lines[^1][^1].isSpaceAscii:
lines[^1].add(" ")
lines[^1].add(content)
lines[^1].appendSameLine(content)
else:
if segment.breakKind == sbParagraph and hasPassageLine:
lines.add("")