A cross platform Audiobookshelf client for Android and iOS
Dart
Keep read along going after a paragraph that ends on an ellipsis or a dash
Barnabasfe0d4c1e02c0
diff --git a/lib/services/read_along_script.dart b/lib/services/read_along_script.dartindex 6ebc703b..37046255 100644--- a/lib/services/read_along_script.dart+++ b/lib/services/read_along_script.dart@@ -224,9 +224,13 @@ const String _body = r'''// "e.g." and "U.S." stay inside one sentence.RA.isTerm = function(raw, i) {var ch = raw[i];- if (ch !== '.' && ch !== '!' && ch !== '?') return false;+ var dash = ch === '\u2014';+ if (ch !== '.' && ch !== '!' && ch !== '?' && ch !== '\u2026' && !dash) return false;var j = i + 1;while (j < raw.length && '"\'”’)]'.indexOf(raw[j]) !== -1) j++;+ // An em dash only ends a sentence when it closes a quote at the end of+ // the paragraph; mid-sentence dashes stay inside it.+ if (dash) return j > i + 1 && (j >= raw.length || raw[j] === '\n');return j >= raw.length || /\s/.test(raw[j]);};diff --git a/lib/utils/passage_match.dart b/lib/utils/passage_match.dartindex a955ae04..9cbb9847 100644--- a/lib/utils/passage_match.dart+++ b/lib/utils/passage_match.dart@@ -249,7 +249,7 @@ String _snapToSentences(String text, int start, int end) {s = i + 1;break;}- if (c == '.' || c == '!' || c == '?') {+ if (c == '.' || c == '!' || c == '?' || c == '\u2026') {s = i + 1;break;}@@ -257,7 +257,7 @@ String _snapToSentences(String text, int start, int end) {final maxE = (end + 260).clamp(0, text.length);for (var i = end; i < maxE; i++) {final c = text[i];- if (c == '.' || c == '!' || c == '?') {+ if (c == '.' || c == '!' || c == '?' || c == '\u2026') {var j = i + 1;while (j < text.length && const ['"', "'", '”', '’'].contains(text[j])) {j++;diff --git a/lib/utils/transcript_align.dart b/lib/utils/transcript_align.dartindex 21c7d6aa..fb06316b 100644--- a/lib/utils/transcript_align.dart+++ b/lib/utils/transcript_align.dart@@ -208,7 +208,11 @@ AlignedText? alignCorrected(List<TimedWord> spoken, String corrected,return (words: out, matched: anchors.length, total: shorter);}-final _endsSentence = RegExp(r'''[.!?]["'”’)\]]*$''');+// A sentence also ends on an ellipsis, or on an em dash that closes a+// quote: dialogue that trails off or is cut short ends its paragraph that+// way, and a line that ran on into the next paragraph left that paragraph's+// first sentence with no line of its own.+final _endsSentence = RegExp(r'''(?:[.!?\u2026]|\u2014["'”’]+)["'”’)\]]*$''');/// [text]'s words timed by a flat per-word estimate from [from] - for the/// preview of book sentences no audio has reached yet.