Exclude <style> tags from quote and underscore italics processing Fixes #3808

7987f02deed19d15beb411bd6290037edfdaaf6b

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

3 files changed, +6 -6Ignore whitespace
public/script.js+1 -1
@@ -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]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gm,2136 /<style>[\s\S]*?<\/style>|```[\s\S]*?```|~~~[\s\S]*?~~~|``[\s\S]*?``|`[\s\S]*?`|(".*?")|(\u201C.*?\u201D)|(\u00AB.*?\u00BB)|(\u300C.*?\u300D)|(\u300E.*?\u300F)|(\uFF02.*?\uFF02)/gim,
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
public/scripts/chats.js+1 -1
@@ -459,7 +459,7 @@ export async function appendFileContent(message, messageText) {
459 * @copyright https://github.com/kwaroran/risuAI459 * @copyright https://github.com/kwaroran/risuAI
460 */460 */
461export function encodeStyleTags(text) {461export function encodeStyleTags(text) {
462 const styleRegex = /<style>(.+?)<\/style>/gms;462 const styleRegex = /<style>(.+?)<\/style>/gims;
463 return text.replaceAll(styleRegex, (_, match) => {463 return text.replaceAll(styleRegex, (_, match) => {
464 return `<custom-style>${escape(match)}</custom-style>`;464 return `<custom-style>${escape(match)}</custom-style>`;
465 });465 });
public/scripts/showdown-underscore.js+4 -4
@@ -8,10 +8,10 @@ export const markdownUnderscoreExt = () => {
88
9 return [{9 return [{
10 type: 'output',10 type: 'output',
11 regex: new RegExp('(<code(?:\\s+[^>]*)?>[\\s\\S]*?<\\/code>)|\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'g'),11 regex: new RegExp('(<code(?:\\s+[^>]*)?>[\\s\\S]*?<\\/code>|<style(?:\\s+[^>]*)?>[\\s\\S]*?<\\/style>)|\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'gi'),
12 replace: function(match, codeContent, italicContent) {12 replace: function(match, tagContent, italicContent) {
13 if (codeContent) {13 if (tagContent) {
14 // If it's inside <code> tags, return unchanged14 // If it's inside <code> or <style> tags, return unchanged
15 return match;15 return match;
16 } else if (italicContent) {16 } else if (italicContent) {
17 // If it's an italic group, apply the replacement17 // If it's an italic group, apply the replacement