Merge pull request #2951 from SillyTavern/intl-quotes

Support more pairs of international quotes
This commit is contained in:
Cohee 2024-10-05 20:31:14 +03:00 committed by GitHub
commit 030313c584
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 9 deletions

View File

@ -2002,15 +2002,33 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
}); });
} }
mes = mes.replace(/```[\s\S]*?```|``[\s\S]*?``|`[\s\S]*?`|(".+?")|(\u201C.+?\u201D)/gm, function (match, p1, p2) { mes = mes.replace(
if (p1) { /```[\s\S]*?```|``[\s\S]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gm,
return '<q>"' + p1.replace(/"/g, '') + '"</q>'; function (match, p1, p2, p3, p4, p5, p6) {
} else if (p2) { if (p1) {
return '<q>“' + p2.replace(/\u201C|\u201D/g, '') + '”</q>'; // English double quotes
} else { return `<q>"${p1.slice(1, -1)}"</q>`;
return match; } else if (p2) {
// Curly double quotes “ ”
return `<q>“${p2.slice(1, -1)}”</q>`;
} else if (p3) {
// Guillemets « »
return `<q>«${p3.slice(1, -1)}»</q>`;
} else if (p4) {
// Corner brackets 「 」
return `<q>「${p4.slice(1, -1)}」</q>`;
} else if (p5) {
// White corner brackets 『 』
return `<q>『${p5.slice(1, -1)}』</q>`;
} else if (p6) {
// Fullwidth quotes
return `<q>${p6.slice(1, -1)}</q>`;
} else {
// Return the original match if no quotes are found
return match;
}
} }
}); );
// Restore double quotes in tags // Restore double quotes in tags
if (!power_user.encode_tags) { if (!power_user.encode_tags) {

View File

@ -474,7 +474,7 @@ async function processTtsQueue() {
} }
if (extension_settings.tts.narrate_quoted_only) { if (extension_settings.tts.narrate_quoted_only) {
const special_quotes = /[“”«»]/g; // Extend this regex to include other special quotes const special_quotes = /[“”«»「」『』""]/g; // Extend this regex to include other special quotes
text = text.replace(special_quotes, '"'); text = text.replace(special_quotes, '"');
const matches = text.match(/".*?"/g); // Matches text inside double quotes, non-greedily const matches = text.match(/".*?"/g); // Matches text inside double quotes, non-greedily
const partJoiner = (ttsProvider?.separator || ' ... '); const partJoiner = (ttsProvider?.separator || ' ... ');