Merge pull request #2951 from SillyTavern/intl-quotes Support more pairs of international quotes

030313c58499fe8d2f307d1ea5997b1c409a1a41

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
2 files changed, +27 -9Ignore whitespace
public/script.js+26 -8
@@ -2002,15 +2002,33 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
2002 });2002 });
2003 }2003 }
20042004
2005 mes = mes.replace(/```[\s\S]*?```|``[\s\S]*?``|`[\s\S]*?`|(".+?")|(\u201C.+?\u201D)/gm, function (match, p1, p2) {2005 mes = mes.replace(
2006 if (p1) {2006 /```[\s\S]*?```|``[\s\S]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gm,
2007 return '<q>"' + p1.replace(/"/g, '') + '"</q>';2007 function (match, p1, p2, p3, p4, p5, p6) {
2008 } else if (p2) {2008 if (p1) {
2009 return '<q>“' + p2.replace(/\u201C|\u201D/g, '') + '”</q>';2009 // English double quotes
2010 } else {2010 return `<q>"${p1.slice(1, -1)}"</q>`;
2011 return match;2011 } else if (p2) {
2012 // Curly double quotes “ ”
2013 return `<q>“${p2.slice(1, -1)}”</q>`;
2014 } else if (p3) {
2015 // Guillemets « »
2016 return `<q>«${p3.slice(1, -1)}»</q>`;
2017 } else if (p4) {
2018 // Corner brackets 「 」
2019 return `<q>「${p4.slice(1, -1)}」</q>`;
2020 } else if (p5) {
2021 // White corner brackets 『 』
2022 return `<q>『${p5.slice(1, -1)}』</q>`;
2023 } else if (p6) {
2024 // Fullwidth quotes " "
2025 return `<q>"${p6.slice(1, -1)}"</q>`;
2026 } else {
2027 // Return the original match if no quotes are found
2028 return match;
2029 }
2012 }2030 }
2013 });2031 );
20142032
2015 // Restore double quotes in tags2033 // Restore double quotes in tags
2016 if (!power_user.encode_tags) {2034 if (!power_user.encode_tags) {
public/scripts/extensions/tts/index.js+1 -1
@@ -474,7 +474,7 @@ async function processTtsQueue() {
474 }474 }
475475
476 if (extension_settings.tts.narrate_quoted_only) {476 if (extension_settings.tts.narrate_quoted_only) {
477 const special_quotes = /[“”«»]/g; // Extend this regex to include other special quotes477 const special_quotes = /[“”«»「」『』""]/g; // Extend this regex to include other special quotes
478 text = text.replace(special_quotes, '"');478 text = text.replace(special_quotes, '"');
479 const matches = text.match(/".*?"/g); // Matches text inside double quotes, non-greedily479 const matches = text.match(/".*?"/g); // Matches text inside double quotes, non-greedily
480 const partJoiner = (ttsProvider?.separator || ' ... ');480 const partJoiner = (ttsProvider?.separator || ' ... ');