Merge pull request #3786 from SillyTavern/tilde-codeblock Improve tilde code blocks in message formatting and TTS processing

469c731ff469d74b29a83050ed21d000e3c6085a

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

Signed
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
21332133 }
21342134
21352135 mes = mes.replace(
21362136 /```[\s\S]*?```|~~~[\s\S]*?~~~|``[\s\S]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gm,
21372137 function (match, p1, p2, p3, p4, p5, p6) {
21382138 if (p1) {
21392139 // English double quotes
@@ -3333,7 +3333,7 @@ class StreamingProcessor {
33333333 stoppingStrings: this.stoppingStrings,
33343334 });
33353335
33363336 const charsToBalance = ['*', '"', '```', '~~~'];
33373337 for (const char of charsToBalance) {
33383338 if (!isFinal && isOdd(countOccurrences(processedText, char))) {
33393339 const separator = char.length > 1 ? '\n' : '';
public/scripts/extensions/tts/index.js+1 -0
@@ -471,6 +471,7 @@ async function processTtsQueue() {
471471 if (extension_settings.tts.skip_codeblocks) {
472472 text = text.replace(/^\s{4}.*$/gm, '').trim();
473473 text = text.replace(/```.*?```/gs, '').trim();
474+ text = text.replace(/~~~.*?~~~/gs, '').trim();
474475 }
475476
476477 if (extension_settings.tts.skip_tags) {