From 1055f2e1b74c2f91afe3aa84d473010174d9a939 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Sat, 5 Oct 2024 20:09:54 +0300
Subject: [PATCH 1/2] Support more pairs of international quotes
---
public/script.js | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/public/script.js b/public/script.js
index 872932e63..6077b0b7c 100644
--- a/public/script.js
+++ b/public/script.js
@@ -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) {
- if (p1) {
- return '"' + p1.replace(/"/g, '') + '"
';
- } else if (p2) {
- return '“' + p2.replace(/\u201C|\u201D/g, '') + '”
';
- } else {
- return match;
+ mes = mes.replace(
+ /```[\s\S]*?```|``[\s\S]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gm,
+ function (match, p1, p2, p3, p4, p5, p6) {
+ if (p1) {
+ // English double quotes
+ return `"${p1.slice(1, -1)}"
`;
+ } else if (p2) {
+ // Curly double quotes “ ”
+ return `“${p2.slice(1, -1)}”
`;
+ } else if (p3) {
+ // Guillemets « »
+ return `«${p3.slice(1, -1)}»
`;
+ } else if (p4) {
+ // Corner brackets 「 」
+ return `「${p4.slice(1, -1)}」
`;
+ } else if (p5) {
+ // White corner brackets 『 』
+ return `『${p5.slice(1, -1)}』
`;
+ } else if (p6) {
+ // Fullwidth quotes " "
+ return `"${p6.slice(1, -1)}"
`;
+ } else {
+ // Return the original match if no quotes are found
+ return match;
+ }
}
- });
+ );
// Restore double quotes in tags
if (!power_user.encode_tags) {
From a5be8898527c2ded026fb1faa0f33c181050a457 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Sat, 5 Oct 2024 20:14:07 +0300
Subject: [PATCH 2/2] Extend quote list for TTS
---
public/scripts/extensions/tts/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js
index 802d51f9c..4c5314af0 100644
--- a/public/scripts/extensions/tts/index.js
+++ b/public/scripts/extensions/tts/index.js
@@ -474,7 +474,7 @@ async function processTtsQueue() {
}
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, '"');
const matches = text.match(/".*?"/g); // Matches text inside double quotes, non-greedily
const partJoiner = (ttsProvider?.separator || ' ... ');