From c0c09f9a5d82cfc6ebc72f9b0af10f69a5ab10e7 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 18 Aug 2024 13:58:47 +0300 Subject: [PATCH 1/5] Don't replace underscore italics inside of code blocks --- public/scripts/showdown-underscore.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/public/scripts/showdown-underscore.js b/public/scripts/showdown-underscore.js index 78a1adef7..cea67cf00 100644 --- a/public/scripts/showdown-underscore.js +++ b/public/scripts/showdown-underscore.js @@ -8,8 +8,16 @@ export const markdownUnderscoreExt = () => { return [{ type: 'lang', - regex: new RegExp('\\b(?$1', + regex: new RegExp('(`{1,3}).*?\\1|\\b(?${italicContent}`; + } + }, }]; } catch (e) { console.error('Error in Showdown-underscore extension:', e); From e137c5d1543a3238683630098504de8515aa75e2 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:15:22 +0300 Subject: [PATCH 2/5] Fix for unmatched single backticks --- public/scripts/showdown-underscore.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/public/scripts/showdown-underscore.js b/public/scripts/showdown-underscore.js index cea67cf00..10ea68b63 100644 --- a/public/scripts/showdown-underscore.js +++ b/public/scripts/showdown-underscore.js @@ -8,15 +8,17 @@ export const markdownUnderscoreExt = () => { return [{ type: 'lang', - regex: new RegExp('(`{1,3}).*?\\1|\\b(?${italicContent}`; + return '' + italicContent + ''; } + // If neither condition is met, return the original match + return match; }, }]; } catch (e) { From 5f3dddfe219c1916e8dbbe181818f4a3788e9754 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:21:50 +0300 Subject: [PATCH 3/5] Fix for unmatched triple backticks --- public/scripts/showdown-underscore.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/scripts/showdown-underscore.js b/public/scripts/showdown-underscore.js index 10ea68b63..d9125c97a 100644 --- a/public/scripts/showdown-underscore.js +++ b/public/scripts/showdown-underscore.js @@ -8,16 +8,16 @@ export const markdownUnderscoreExt = () => { return [{ type: 'lang', - regex: new RegExp('(`{3})[\\s\\S]*?\\1|(`{1,2}).*?\\2|\\b(?' + italicContent + ''; } - // If neither condition is met, return the original match + // If none of the conditions are met, return the original match return match; }, }]; From f8dbe262c72eb3bb11a56e399ab5f668d253f739 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:22:31 +0300 Subject: [PATCH 4/5] Fix for single backticks with line breaks --- public/scripts/showdown-underscore.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/scripts/showdown-underscore.js b/public/scripts/showdown-underscore.js index d9125c97a..08f0d5aa4 100644 --- a/public/scripts/showdown-underscore.js +++ b/public/scripts/showdown-underscore.js @@ -8,10 +8,10 @@ export const markdownUnderscoreExt = () => { return [{ type: 'lang', - regex: /(`{3,})\s*\n[\s\S]*?\n\1(?:\n|$)|(`{1,2}).*?\2|(? Date: Mon, 19 Aug 2024 01:26:27 +0300 Subject: [PATCH 5/5] Replace underscores in HTML output --- public/scripts/showdown-underscore.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/scripts/showdown-underscore.js b/public/scripts/showdown-underscore.js index 08f0d5aa4..bc7743d7b 100644 --- a/public/scripts/showdown-underscore.js +++ b/public/scripts/showdown-underscore.js @@ -7,11 +7,11 @@ export const markdownUnderscoreExt = () => { } return [{ - type: 'lang', - regex: /(`{3,})\s*\n[\s\S]*?\n\1(?:\n|$)|(`{1,2}).*?\2|(\n`\n[\s\S]*?\n`\n)|(?[\\s\\S]*?<\\/code>)|(? tags, return unchanged return match; } else if (italicContent) { // If it's an italic group, apply the replacement