Skip to content

Commit a2b7a2b

Browse files
committed
Fix BibleGateway verse extraction to get last number in class
BibleGateway HTML uses classes like 'Gen-1-1', 'Gen-1-2' where the last number is the verse number. Previous regex '\b(\d+)\b' matched the FIRST number (the chapter), causing all verses to be numbered as 1. Fixed with '-(\d+)$' to extract the verse number correctly. Fixes 'only getting first verse' issue in Metanoia Bible app.
1 parent cbeeacf commit a2b7a2b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

mobile/app/src/main/java/com/bytecats/metanoia/bible/BibleScraper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class BibleScraper(
3636
val doc = Jsoup.parse(body)
3737
doc.select("h1, h2, h3, h4, h5, h6").remove()
3838
doc.select("div.passage-text span.text").forEach { span ->
39-
// Get classes as a single string (Jsoup returns space-separated)
39+
// BibleGateway uses classes like "Gen-1-1", "Gen-1-2" (Book-Chapter-Verse)
40+
// Extract the verse number (last number after last dash)
4041
val className = span.className()
41-
// Match any class that ends with dash-digit pattern
42-
val verseNum = Regex("\\b(\\d+)\\b").find(className)?.groupValues?.get(1)?.toInt()
42+
val verseNum = Regex("-(\\d+)$").find(className)?.groupValues?.get(1)?.toInt()
4343
if (verseNum != null) {
4444
span.select("sup, span.chapternum, span.versenum").remove()
4545
onVerse(verseNum, span.text().trim())

0 commit comments

Comments
 (0)