Improve tilde code blocks in message formatting and TTS processing

This commit is contained in:
Cohee
2025-03-30 13:25:15 +03:00
parent 60603a008c
commit 65a6e428d1
2 changed files with 3 additions and 2 deletions

View File

@@ -2133,7 +2133,7 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
}
mes = mes.replace(
/```[\s\S]*?```|``[\s\S]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gm,
/```[\s\S]*?```|~~~[\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
@@ -3333,7 +3333,7 @@ class StreamingProcessor {
stoppingStrings: this.stoppingStrings,
});
const charsToBalance = ['*', '"', '```'];
const charsToBalance = ['*', '"', '```', '~~~'];
for (const char of charsToBalance) {
if (!isFinal && isOdd(countOccurrences(processedText, char))) {
const separator = char.length > 1 ? '\n' : '';

View File

@@ -471,6 +471,7 @@ async function processTtsQueue() {
if (extension_settings.tts.skip_codeblocks) {
text = text.replace(/^\s{4}.*$/gm, '').trim();
text = text.replace(/```.*?```/gs, '').trim();
text = text.replace(/~~~.*?~~~/gs, '').trim();
}
if (extension_settings.tts.skip_tags) {