From 1da8fb5da93f9623ce975369a1d4e67eee4d8ba8 Mon Sep 17 00:00:00 2001
From: Sankalp Tripathi
Date: Fri, 17 Oct 2025 12:35:03 +0530
Subject: [PATCH] fix: resolve even-numbered backtick precedence issue (#3776)
(#3786)
Co-authored-by: Tony Brix
---
src/rules.ts | 4 +++-
.../new/issue_3776_backtick_precedence.html | 9 +++++++++
.../specs/new/issue_3776_backtick_precedence.md | 17 +++++++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 test/specs/new/issue_3776_backtick_precedence.html
create mode 100644 test/specs/new/issue_3776_backtick_precedence.md
diff --git a/src/rules.ts b/src/rules.ts
index 7e00f700..e2c48754 100644
--- a/src/rules.ts
+++ b/src/rules.ts
@@ -267,7 +267,9 @@ const _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
// sequences em should skip over [title](link), `code`,
-const blockSkip = /\[(?:[^\[\]`]|`[^`]*?`)*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g;
+const blockSkip = edit(/\[(?:[^\[\]`]|`[^`]*?`)*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|codePattern|<(?! )[^<>]*?>/, 'g')
+ .replace('codePattern', /(?**You might think this should be bold, but: **
+**You might think this should be bold, but: **
+**You might think this should be bold, but: **
+**You might think this should be bold, but: **
+This should be bold and this should be code
+start contains ** end
+This should be bold ```
+This should be bold ```
+start contains ** end
\ No newline at end of file
diff --git a/test/specs/new/issue_3776_backtick_precedence.md b/test/specs/new/issue_3776_backtick_precedence.md
new file mode 100644
index 00000000..2db6949a
--- /dev/null
+++ b/test/specs/new/issue_3776_backtick_precedence.md
@@ -0,0 +1,17 @@
+**You might think this should be bold, but: `**`
+
+**You might think this should be bold, but: ``**``
+
+**You might think this should be bold, but: ```**```
+
+**You might think this should be bold, but: ````**````
+
+**This should be bold** and `this should be code`
+
+**start `contains **` end**
+
+**This should be bold ``**`
+
+**This should be bold `**``
+
+**start ``contains **`` end**
\ No newline at end of file