From 21ab0b6d4bcad03b9cf69b3d43531aa175413d51 Mon Sep 17 00:00:00 2001 From: Nikita Barinov Date: Tue, 10 Mar 2026 11:13:01 +0100 Subject: [PATCH 01/10] fix: prevent single-tilde strikethrough false positives When a closing single ~ is followed by an alphanumeric character, skip the strikethrough match since it fails GFM right-flanking delimiter rules. This prevents text like `~125 GeV ... **~173 GeV**` from being incorrectly parsed as strikethrough. --- src/Tokenizer.ts | 7 +++++++ test/specs/new/del_flanking.html | 1 + test/specs/new/del_flanking.md | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 1e821e6af8..0eb6e8c20e 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -866,6 +866,13 @@ export class _Tokenizer { // Create del token - only single ~ or double ~~ supported const text = raw.slice(lLength, -lLength); + + // For single ~, skip if closing ~ is followed by an alphanumeric character. + // Prevents e.g. `~125 GeV, while the top quark is **~173 GeV**` from matching as strikethrough, + // since the closing ~ fails GFM right-flanking delimiter rules. + // See https://github.github.com/gfm/#emphasis-and-strong-emphasis + if (lLength === 1 && raw.length < src.length && /[0-9a-zA-Z]/.test(src[raw.length])) continue; + return { type: 'del', raw, diff --git a/test/specs/new/del_flanking.html b/test/specs/new/del_flanking.html index f097b7339b..df15a8ca1b 100644 --- a/test/specs/new/del_flanking.html +++ b/test/specs/new/del_flanking.html @@ -3,3 +3,4 @@

Between (~1.34) and (~5.4)

~ test~

~test ~

+

The mass of the Higgs boson is ~125 GeV, while the top quark is ~173 GeV

diff --git a/test/specs/new/del_flanking.md b/test/specs/new/del_flanking.md index 9f93a3b388..a06d49e171 100644 --- a/test/specs/new/del_flanking.md +++ b/test/specs/new/del_flanking.md @@ -7,3 +7,5 @@ Between (~1.34) and (~5.4) ~ test~ ~test ~ + +The mass of the Higgs boson is ~125 GeV, while the top quark is **~173 GeV** From a92a300cde8cff60246d9013065082e08e555495 Mon Sep 17 00:00:00 2001 From: Nikita Barinov Date: Tue, 10 Mar 2026 21:33:37 +0100 Subject: [PATCH 02/10] fix: use unicode alphanumeric check in strikethrough delimiter --- src/Tokenizer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 0eb6e8c20e..aafbcba72f 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -871,7 +871,7 @@ export class _Tokenizer { // Prevents e.g. `~125 GeV, while the top quark is **~173 GeV**` from matching as strikethrough, // since the closing ~ fails GFM right-flanking delimiter rules. // See https://github.github.com/gfm/#emphasis-and-strong-emphasis - if (lLength === 1 && raw.length < src.length && /[0-9a-zA-Z]/.test(src[raw.length])) continue; + if (lLength === 1 && raw.length < src.length && this.rules.other.unicodeAlphaNumeric.test(src[raw.length])) continue; return { type: 'del', From b5d0a7f4c540fda4be77deb6990ba47926b74be8 Mon Sep 17 00:00:00 2001 From: Nikita Barinov Date: Wed, 11 Mar 2026 10:22:11 +0100 Subject: [PATCH 03/10] fix: also check char before closing tilde to preserve valid strikethrough --- src/Tokenizer.ts | 12 ++++++++---- test/specs/new/del_strikethrough.html | 1 + test/specs/new/del_strikethrough.md | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index aafbcba72f..49cae662c0 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -867,11 +867,15 @@ export class _Tokenizer { // Create del token - only single ~ or double ~~ supported const text = raw.slice(lLength, -lLength); - // For single ~, skip if closing ~ is followed by an alphanumeric character. - // Prevents e.g. `~125 GeV, while the top quark is **~173 GeV**` from matching as strikethrough, - // since the closing ~ fails GFM right-flanking delimiter rules. + // For single ~, skip if closing ~ is not right-flanking per GFM rules: + // the closing ~ must be preceded by a non-whitespace, non-punctuation char (alphanumeric) + // to be right-flanking. If followed by alphanumeric but NOT preceded by alphanumeric, + // it fails the right-flanking delimiter test. // See https://github.github.com/gfm/#emphasis-and-strong-emphasis - if (lLength === 1 && raw.length < src.length && this.rules.other.unicodeAlphaNumeric.test(src[raw.length])) continue; + if (lLength === 1 + && raw.length < src.length + && this.rules.other.unicodeAlphaNumeric.test(src[raw.length]) + && !this.rules.other.unicodeAlphaNumeric.test(src[raw.length - 2])) continue; return { type: 'del', diff --git a/test/specs/new/del_strikethrough.html b/test/specs/new/del_strikethrough.html index 980134aa21..0e25552c54 100644 --- a/test/specs/new/del_strikethrough.html +++ b/test/specs/new/del_strikethrough.html @@ -13,4 +13,5 @@

test~~

+

1 a2

diff --git a/test/specs/new/del_strikethrough.md b/test/specs/new/del_strikethrough.md index f3d5bca081..d72adfad45 100644 --- a/test/specs/new/del_strikethrough.md +++ b/test/specs/new/del_strikethrough.md @@ -13,4 +13,6 @@ test~~ test~~ +~1 a~2 + ~~~test~~~ From e24034e1767c07a4b06bb048aa71baa11adfcad5 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 14 Mar 2026 23:52:54 -0600 Subject: [PATCH 04/10] Refactor strikethrough rule Removed GFM specific regex patterns for strikethrough and replaced them with general punctuation patterns. --- src/rules.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/rules.ts b/src/rules.ts index fd77781ea3..6b1ed33138 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -277,11 +277,6 @@ const _punctuationGfmStrongEm = /(?!~)[\p{P}\p{S}]/u; const _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u; const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u; -// GFM allows * and _ inside strikethrough -const _punctuationGfmDel = /(?![*_])[\p{P}\p{S}]/u; -const _punctuationOrSpaceGfmDel = /(?![*_])[\s\p{P}\p{S}]/u; -const _notPunctuationOrSpaceGfmDel = /(?:[^\s\p{P}\p{S}]|[*_])/u; - // sequences em should skip over [title](link), `code`, const blockSkip = edit(/link|precode-code|html/, 'g') .replace('link', /\[(?:[^\[\]`]|(?`+)[^`]+\k(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/) @@ -338,7 +333,7 @@ const emStrongRDelimUnd = edit( // Tilde left delimiter for strikethrough (similar to emStrongLDelim for asterisk) const delLDelim = edit(/^~~?(?:((?!~)punct)|[^\s~])/, 'u') - .replace(/punct/g, _punctuationGfmDel) + .replace(/punct/g, _punctuation) .getRegex(); // Tilde delimiter patterns for strikethrough (similar to asterisk) @@ -352,9 +347,9 @@ const delRDelimCore = + '|notPunctSpace(~~?)(?=notPunctSpace)'; // (6) a~~a can be either Left or Right Delimiter const delRDelim = edit(delRDelimCore, 'gu') - .replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmDel) - .replace(/punctSpace/g, _punctuationOrSpaceGfmDel) - .replace(/punct/g, _punctuationGfmDel) + .replace(/notPunctSpace/g, _notPunctuationOrSpace) + .replace(/punctSpace/g, _punctuationOrSpace) + .replace(/punct/g, _punctuation) .getRegex(); const anyPunctuation = edit(/\\(punct)/, 'gu') From aa345863633e608c66dc3ee716674223f72c39ae Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 14 Mar 2026 23:53:44 -0600 Subject: [PATCH 05/10] Remove tokenizer changes --- src/Tokenizer.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 49cae662c0..b7247661f9 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -867,16 +867,6 @@ export class _Tokenizer { // Create del token - only single ~ or double ~~ supported const text = raw.slice(lLength, -lLength); - // For single ~, skip if closing ~ is not right-flanking per GFM rules: - // the closing ~ must be preceded by a non-whitespace, non-punctuation char (alphanumeric) - // to be right-flanking. If followed by alphanumeric but NOT preceded by alphanumeric, - // it fails the right-flanking delimiter test. - // See https://github.github.com/gfm/#emphasis-and-strong-emphasis - if (lLength === 1 - && raw.length < src.length - && this.rules.other.unicodeAlphaNumeric.test(src[raw.length]) - && !this.rules.other.unicodeAlphaNumeric.test(src[raw.length - 2])) continue; - return { type: 'del', raw, From ddf787379ba0d693d09191982d7e576c38abdc13 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 14 Mar 2026 23:54:25 -0600 Subject: [PATCH 06/10] Fix formatting in Tokenizer.ts --- src/Tokenizer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index b7247661f9..1e821e6af8 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -866,7 +866,6 @@ export class _Tokenizer { // Create del token - only single ~ or double ~~ supported const text = raw.slice(lLength, -lLength); - return { type: 'del', raw, From a720f0008629803fa729683f42f34d541a59c5ca Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 14 Mar 2026 23:55:18 -0600 Subject: [PATCH 07/10] Update del_strikethrough.md with new test cases --- test/specs/new/del_strikethrough.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/specs/new/del_strikethrough.md b/test/specs/new/del_strikethrough.md index d72adfad45..814d5b8d20 100644 --- a/test/specs/new/del_strikethrough.md +++ b/test/specs/new/del_strikethrough.md @@ -15,4 +15,6 @@ test~~ ~1 a~2 +~~1 a~~2 + ~~~test~~~ From 70e380a7d754a93c56612516757740c593c20e62 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 14 Mar 2026 23:55:44 -0600 Subject: [PATCH 08/10] Fix strikethrough HTML syntax in del_strikethrough.html --- test/specs/new/del_strikethrough.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/specs/new/del_strikethrough.html b/test/specs/new/del_strikethrough.html index 0e25552c54..416de2af8c 100644 --- a/test/specs/new/del_strikethrough.html +++ b/test/specs/new/del_strikethrough.html @@ -14,4 +14,7 @@

test~~

1 a2

+ +

1 a2

+
From 102bda090e1ff7c1127fd16865ff574b48355d2a Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 14 Mar 2026 23:56:24 -0600 Subject: [PATCH 09/10] Update Higgs boson mass and add new entry --- test/specs/new/del_flanking.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/specs/new/del_flanking.md b/test/specs/new/del_flanking.md index a06d49e171..6eeb2981a9 100644 --- a/test/specs/new/del_flanking.md +++ b/test/specs/new/del_flanking.md @@ -9,3 +9,5 @@ Between (~1.34) and (~5.4) ~test ~ The mass of the Higgs boson is ~125 GeV, while the top quark is **~173 GeV** + +~~1 **~~2** From 350f0635d3bfedd5a6484ca0b269d950e8d7e417 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 14 Mar 2026 23:56:53 -0600 Subject: [PATCH 10/10] Add new paragraph with Higgs boson mass details --- test/specs/new/del_flanking.html | 1 + 1 file changed, 1 insertion(+) diff --git a/test/specs/new/del_flanking.html b/test/specs/new/del_flanking.html index df15a8ca1b..1cfcec7719 100644 --- a/test/specs/new/del_flanking.html +++ b/test/specs/new/del_flanking.html @@ -4,3 +4,4 @@

~ test~

~test ~

The mass of the Higgs boson is ~125 GeV, while the top quark is ~173 GeV

+

~~1 ~~2