Merge pull request #1780 from Spacellary/patch-1

(Small) Add Handling for Dangling Characters in "trimToEndSentence" - utils.js
This commit is contained in:
Cohee 2024-02-02 21:34:51 +02:00 committed by GitHub
commit 17a783f9c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 2 deletions

View File

@ -471,14 +471,18 @@ export function sortByCssOrder(a, b) {
* trimToEndSentence('Hello, world! I am from'); // 'Hello, world!'
*/
export function trimToEndSentence(input, include_newline = false) {
const punctuation = new Set(['.', '!', '?', '*', '"', ')', '}', '`', ']', '$', '。', '', '', '”', '', '】', '】', '', '」', '】']); // extend this as you see fit
const punctuation = new Set(['.', '!', '?', '*', '"', ')', '}', '`', ']', '$', '。', '', '', '”', '', '】', '', '」']); // extend this as you see fit
let last = -1;
for (let i = input.length - 1; i >= 0; i--) {
const char = input[i];
if (punctuation.has(char)) {
last = i;
if (i > 0 && /[\s\n]/.test(input[i - 1])) {
last = i - 1;
} else {
last = i;
}
break;
}