fix: sentence count stalls on long unpunctuated pages (#36)

This commit is contained in:
Alvin Cheung authored and GitHub committed 2026-10-17 11:41:21 +03:00
1 parent e31fd1f367
commit 865a25aba4
1 file changed
+4 -2
+4 -2
View File
@@ -2604,8 +2604,10 @@ function computeReadability(text: string, wordCount: number): ReadabilityScores
}
// Sentence boundary heuristic: . / ! / ? / … followed by whitespace or
// end of text. Multiple terminators collapse into one. Newline already
// collapsed to single space upstream.
const sentenceMatches = text.match(/[^.!?…]+[.!?…]+/g);
// collapsed to single space upstream. Counting each non-terminator ->
// terminator boundary gives the same count as `/[^.!?…]+[.!?…]+/g`,
// which backtracks quadratically on a long unterminated run of text.
const sentenceMatches = text.match(/[^.!?…][.!?…]/g);
const sentenceCount = sentenceMatches ? sentenceMatches.length : 1;
let totalSyllables = 0;