// "Luke 1, Luke 2, Luke 3, Luke 5" -> "Luke 1–3, 5": a long run of chapters reads as ranges, so a // study card stays short. Anything that isn't "Book N" is left as it was. export function compactPassages(summary) { if (!summary) return ''; const parts = summary.split(/,\s*/); const groups = []; for (const part of parts) { const m = part.match(/^(.+?)\s+(\d+)$/); if (!m) { groups.push({ raw: part }); continue; } const last = groups[groups.length - 1]; if (last && last.book === m[1]) last.chapters.push(Number(m[2])); else groups.push({ book: m[1], chapters: [Number(m[2])] }); } return groups.map((g) => { if (g.raw !== undefined) return g.raw; const runs = []; for (const n of g.chapters) { const run = runs[runs.length - 1]; if (run && n === run[1] + 1) run[1] = n; else runs.push([n, n]); } return `${g.book} ${runs.map(([a, b]) => (a === b ? a : b === a + 1 ? `${a}, ${b}` : `${a}–${b}`)).join(', ')}`; }).join(', '); }