Improve tilde code blocks in message formatting and TTS processing

65a6e428d1c705a8ace3efd6a406e26e4672b0cb

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

2 files changed, +3 -2Showing whitespace changes
public/script.js+2 -2
@@ -2133,7 +2133,7 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
2133 }2133 }
21342134
2135 mes = mes.replace(2135 mes = mes.replace(
2136 /```[\s\S]*?```|``[\s\S]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gm,2136 /```[\s\S]*?```|~~~[\s\S]*?~~~|``[\s\S]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gm,
2137 function (match, p1, p2, p3, p4, p5, p6) {2137 function (match, p1, p2, p3, p4, p5, p6) {
2138 if (p1) {2138 if (p1) {
2139 // English double quotes2139 // English double quotes
@@ -3333,7 +3333,7 @@ class StreamingProcessor {
3333 stoppingStrings: this.stoppingStrings,3333 stoppingStrings: this.stoppingStrings,
3334 });3334 });
33353335
3336 const charsToBalance = ['*', '"', '```'];3336 const charsToBalance = ['*', '"', '```', '~~~'];
3337 for (const char of charsToBalance) {3337 for (const char of charsToBalance) {
3338 if (!isFinal && isOdd(countOccurrences(processedText, char))) {3338 if (!isFinal && isOdd(countOccurrences(processedText, char))) {
3339 const separator = char.length > 1 ? '\n' : '';3339 const separator = char.length > 1 ? '\n' : '';
public/scripts/extensions/tts/index.js+1 -0
@@ -471,6 +471,7 @@ async function processTtsQueue() {
471 if (extension_settings.tts.skip_codeblocks) {471 if (extension_settings.tts.skip_codeblocks) {
472 text = text.replace(/^\s{4}.*$/gm, '').trim();472 text = text.replace(/^\s{4}.*$/gm, '').trim();
473 text = text.replace(/```.*?```/gs, '').trim();473 text = text.replace(/```.*?```/gs, '').trim();
474 text = text.replace(/~~~.*?~~~/gs, '').trim();
474 }475 }
475476
476 if (extension_settings.tts.skip_tags) {477 if (extension_settings.tts.skip_tags) {