From 8dc1adc9f02d9e3eca257b45c3beba058d71530e Mon Sep 17 00:00:00 2001 From: chylex Date: Thu, 21 Dec 2023 05:08:46 +0100 Subject: [PATCH] Fix viewer converting underscores to italics even when not at the end of a word --- app/Resources/Viewer/scripts/discord.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Resources/Viewer/scripts/discord.js b/app/Resources/Viewer/scripts/discord.js index 9d576cc..90f71b1 100644 --- a/app/Resources/Viewer/scripts/discord.js +++ b/app/Resources/Viewer/scripts/discord.js @@ -1,7 +1,8 @@ const DISCORD = (function() { const regex = { formatBold: /\*\*([\s\S]+?)\*\*(?!\*)/g, - formatItalic: /(.)?([_*])([\s\S]+?)\2(?!\2)/g, + formatItalic1: /\*([\s\S]+?)\*(?!\*)/g, + formatItalic2: /_([\s\S]+?)_(?!_)\b/g, formatUnderline: /__([\s\S]+?)__(?!_)/g, formatStrike: /~~([\s\S]+?)~~(?!~)/g, formatCodeInline: /(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/g, @@ -48,7 +49,8 @@ const DISCORD = (function() { .replace(regex.specialEscapedDouble, full => full.replace(/\\/g, "").replace(/(.)/g, escapeHtmlMatch)) .replace(regex.formatBold, "$1") .replace(regex.formatUnderline, "$1") - .replace(regex.formatItalic, (full, pre, char, match) => pre === "\\" ? full : (pre || "") + "" + match + "") + .replace(regex.formatItalic1, "$1") + .replace(regex.formatItalic2, "$1") .replace(regex.formatStrike, "$1"); }