diff --git a/backend/src/search.js b/backend/src/search.js index 77ae6829..6f8ca218 100644 --- a/backend/src/search.js +++ b/backend/src/search.js @@ -8,39 +8,50 @@ class BibleSearchEngine { this.isIndexed = false; } - // Parse verses from markdown content + // Parse verses from markdown content (handles multi-line verses) parseVersesFromMarkdown(content, book, chapter) { const verses = []; const lines = content.split('\n'); - - for (let i = 0; i < lines.length; i++) { - const line = lines[i].trim(); - + let currentVerse = null; + + for (const line of lines) { + const trimmedLine = line.trim(); + // Skip empty lines and headers - if (!line || line.startsWith('#')) { + if (!trimmedLine || trimmedLine.startsWith('#')) { continue; } - - // Match verse patterns: - // - "1. In the beginning..." (numbered list format) - // - "1 In the beginning..." (simple number format) - // - "**1** In the beginning..." (bold number format) - const verseMatch = line.match(/^(\*\*)?(\d+)(\*\*)?[.\s]\s*(.+)$/); - + + const verseMatch = trimmedLine.match(/^(\*\*)?(\d+)(\*\*)?[.\s]\s*(.*)$/); + if (verseMatch) { + // If a new verse is found, save the previous one + if (currentVerse) { + verses.push(currentVerse); + } + const verseNumber = parseInt(verseMatch[2]); const verseText = verseMatch[4]; - verses.push({ + currentVerse = { book, chapter, verse: verseNumber, text: verseText, - fullText: line - }); + fullText: trimmedLine + }; + } else if (currentVerse) { + // If it's a continuation of the current verse, append the text + currentVerse.text += ` ${trimmedLine}`; + currentVerse.fullText += `\n${trimmedLine}`; } } - + + // Add the last verse + if (currentVerse) { + verses.push(currentVerse); + } + return verses; }