diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 15:10:45 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 15:10:45 +0200 |
| commit | 28699aa44df1d791fb48618a8f06627f230432d4 (patch) | |
| tree | 85d9bd7aa376eb6077de69b65aaa877ab428ae05 /internal/bible/booktable.go | |
| parent | 0b33a068df10971eff8a369d14c3dcca5ae5ed98 (diff) | |
| download | lectio-28699aa44df1d791fb48618a8f06627f230432d4.tar.gz lectio-28699aa44df1d791fb48618a8f06627f230432d4.zip | |
fix(bible): resolve + format cross-chapter citations (13:22-25; 15:10)
normalizeSigla treats ';' as a group separator so SplitRef resolves each
chapter; FormatRef renders multi-chapter refs per chapter in the dialect's
sigla. Restored the full Assumption (Judith 13:22-25; 15:10) and St Lucy
(2 Cor 10:17-18; 11:1-2) epistles.
Diffstat (limited to 'internal/bible/booktable.go')
| -rw-r--r-- | internal/bible/booktable.go | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/internal/bible/booktable.go b/internal/bible/booktable.go index ae005a5..de8995c 100644 --- a/internal/bible/booktable.go +++ b/internal/bible/booktable.go @@ -186,16 +186,45 @@ func (t *BookTable) FormatRef(dialect, canonicalRef string) string { if m == nil { return canonicalRef } - canon, chap, verses := m[1], m[2], m[3] + canon, chap, rest := m[1], m[2], m[3] abbrev := t.shortcut(dialect, canon) if abbrev == "" { return canonicalRef } + // rest is a comma-separated group list; a group with ":" opens a new chapter. + var b strings.Builder + b.WriteString(abbrev + " ") + for i, g := range strings.Split(rest, ",") { + g = strings.TrimSpace(g) + if g == "" { + continue + } + newChap := "" + if idx := strings.IndexByte(g, ':'); idx >= 0 { + newChap, g = g[:idx], g[idx+1:] + } + switch { + case i == 0: // first group uses the chapter from refRe + b.WriteString(chapVerse(dialect, chap, g)) + case newChap != "" && newChap != chap: // cross-chapter group + chap = newChap + b.WriteString("; " + chapVerse(dialect, chap, g)) + case dialect == "pl": // another verse group in the same chapter + b.WriteString(". " + g) + default: + b.WriteString("," + g) + } + } + return b.String() +} + +// chapVerse renders one "chapter + verses" in the dialect's style: English +// "5:15-17", Polish "5, 15-17". +func chapVerse(dialect, chap, verses string) string { if dialect == "pl" { - verses = strings.ReplaceAll(verses, ",", ". ") // disjoint groups - return abbrev + " " + chap + ", " + verses + return chap + ", " + verses } - return abbrev + " " + chap + ":" + verses + return chap + ":" + verses } // normalizeSigla rewrites a dialect's verse-reference tail into the colon/comma @@ -213,6 +242,9 @@ func normalizeSigla(dialect, tail string) string { } else { tail = strings.ReplaceAll(tail, ".", ",") // disjoint groups (comma already fine) } + // A semicolon separates cross-chapter groups ("13:22-25; 15:10"); treat it + // as a group separator so bible.SplitRef resolves each chapter. + tail = strings.ReplaceAll(tail, ";", ",") tail = dashRe.ReplaceAllString(tail, "-") tail = verseLetterRe.ReplaceAllString(tail, "$1") tail = strings.ReplaceAll(tail, " ", "") |
