From 8f1c91b2cc7f268415d37d055cf73aa2ccf86c63 Mon Sep 17 00:00:00 2001 From: chylex Date: Sat, 4 Jun 2022 22:09:24 +0200 Subject: [PATCH] Fix not formatting single underscores as italics in the viewer Closes #142 --- app/Resources/Viewer/scripts/discord.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Resources/Viewer/scripts/discord.js b/app/Resources/Viewer/scripts/discord.js index f9a2d1a..71e96b7 100644 --- a/app/Resources/Viewer/scripts/discord.js +++ b/app/Resources/Viewer/scripts/discord.js @@ -1,7 +1,7 @@ const DISCORD = (function() { const regex = { formatBold: /\*\*([\s\S]+?)\*\*(?!\*)/g, - formatItalic: /(.)?\*([\s\S]+?)\*(?!\*)/g, + formatItalic: /(.)?([_*])([\s\S]+?)\2(?!\2)/g, formatUnderline: /__([\s\S]+?)__(?!_)/g, formatStrike: /~~([\s\S]+?)~~(?!~)/g, formatCodeInline: /(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/g, @@ -9,7 +9,7 @@ const DISCORD = (function() { formatUrl: /(\b(?:https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, formatUrlNoEmbed: /<(\b(?:https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])>/ig, specialEscapedBacktick: /\\`/g, - specialEscapedSingle: /\\([*\\])/g, + specialEscapedSingle: /\\([*_\\])/g, specialEscapedDouble: /\\__|_\\_|\\_\\_|\\~~|~\\~|\\~\\~/g, specialUnescaped: /([*_~\\])/g, mentionRole: /<@&(\d+?)>/g, @@ -47,8 +47,8 @@ const DISCORD = (function() { .replace(regex.specialEscapedSingle, escapeHtmlMatch) .replace(regex.specialEscapedDouble, full => full.replace(/\\/g, "").replace(/(.)/g, escapeHtmlMatch)) .replace(regex.formatBold, "$1") - .replace(regex.formatItalic, (full, pre, match) => pre === "\\" ? full : (pre || "") + "" + match + "") .replace(regex.formatUnderline, "$1") + .replace(regex.formatItalic, (full, pre, char, match) => pre === "\\" ? full : (pre || "") + "" + match + "") .replace(regex.formatStrike, "$1"); }