From 11ad43186a0d1eb49835bf6cd4e218176b8cd19a Mon Sep 17 00:00:00 2001 From: Joseph Meis Date: Tue, 26 Aug 2025 17:48:58 -0500 Subject: [PATCH 1/2] fix(markdown.js): use proposed fixes using negative look-ahead --- mode/markdown/markdown.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mode/markdown/markdown.js b/mode/markdown/markdown.js index 6eef54427f..195805210a 100644 --- a/mode/markdown/markdown.js +++ b/mode/markdown/markdown.js @@ -484,7 +484,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { } } - if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) { + if (ch === '!' && stream.match(/\[[^\]\n]*](?=\(|\[)/, false)) { state.imageMarker = true; state.image = true; if (modeCfg.highlightFormatting) state.formatting = "image"; @@ -518,7 +518,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { if (modeCfg.highlightFormatting) state.formatting = "link"; var type = getType(state); state.linkText = false; - state.inline = state.f = stream.match(/\(.*?\)| ?\[.*?\]/, false) ? linkHref : inlineNormal + state.inline = state.f = stream.match(/\(([^()]*|\(([^()]*)\))*\)| ?\[(?:[^\]\\]|\\.)*]/, false) ? linkHref : inlineNormal return type; } @@ -534,7 +534,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { return type + tokenTypes.linkInline; } - if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) { + if (ch === '<' && stream.match(/^[^\s>@]+@[^>\s]+>/, false)) { state.f = state.inline = linkInline; if (modeCfg.highlightFormatting) state.formatting = "link"; var type = getType(state); From 7382be2351b18f9054b97b87db0d712c6493ec72 Mon Sep 17 00:00:00 2001 From: Joseph Meis Date: Wed, 27 Aug 2025 14:58:09 -0500 Subject: [PATCH 2/2] fix(markdown.js): use new regex fixes provided by ShiyuBanzhou --- mode/markdown/markdown.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mode/markdown/markdown.js b/mode/markdown/markdown.js index 195805210a..41e9e75f44 100644 --- a/mode/markdown/markdown.js +++ b/mode/markdown/markdown.js @@ -484,7 +484,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { } } - if (ch === '!' && stream.match(/\[[^\]\n]*](?=\(|\[)/, false)) { + if (ch === '!' && stream.match(/\[(?:[^\]\n]){0,1000}\](?= ?(?:\(|\[))/, false)) { state.imageMarker = true; state.image = true; if (modeCfg.highlightFormatting) state.formatting = "image"; @@ -518,7 +518,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { if (modeCfg.highlightFormatting) state.formatting = "link"; var type = getType(state); state.linkText = false; - state.inline = state.f = stream.match(/\(([^()]*|\(([^()]*)\))*\)| ?\[(?:[^\]\\]|\\.)*]/, false) ? linkHref : inlineNormal + state.inline = state.f = stream.match(/\((?:[^()\n\\]|\\.){0,1000}\)| ?\[(?:[^\[\]\n\\]|\\.){0,1000}\]/, false) ? linkHref : inlineNormal return type; } @@ -534,7 +534,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { return type + tokenTypes.linkInline; } - if (ch === '<' && stream.match(/^[^\s>@]+@[^>\s]+>/, false)) { + if (ch === '<' && stream.match(/^[^\s>@]{1,64}@[^\s>]{1,255}>/, false)) { state.f = state.inline = linkInline; if (modeCfg.highlightFormatting) state.formatting = "link"; var type = getType(state);