fix: let a mid-run opener close against a delimiter that can also open (#4203)

This commit is contained in:
yash
2026-11-16 09:27:25 -07:00
committed by GitHub
parent 7499eb3a23
commit 06e1d10903
3 changed files with 30 additions and 7 deletions
+8 -7
View File
@@ -1033,14 +1033,15 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
delimTotal += rLength;
continue;
} else if (match[5] || match[6] || openerCanClose) { // either Left or Right Delim
if (midRun && (match[5] || match[6])) {
// A mid-run opener cannot close against an ambiguous delimiter that
// can also open; that delimiter opens its own emphasis span instead.
break;
}
if (runLength % 3 && !((runLength + rLength) % 3)) {
if (runLength % 3 && !((runLength + rLength) % 3)) { // CommonMark Emphasis Rules 9-10
if (midRun && (match[5] || match[6])) {
// A delimiter that can also open and cannot close this run
// opens its own span; a later closer pairs with it, not with a
// mid-run opener (`**a*a*` must be `**a<em>a</em>`).
break;
}
midDelimTotal += rLength;
continue; // CommonMark Emphasis Rules 9-10
continue;
}
}
@@ -0,0 +1,11 @@
<p>**<em>a</em>a</p>
<p>*<strong>a</strong>a</p>
<p>*<em><em>a</em>a</em></p>
<p>***<em>a</em>a</p>
<p>-**<em>[h]</em>&quot;a</p>
<p>**a<em>a</em></p>
@@ -0,0 +1,11 @@
***a*a
***a**a
***a*a*
****a*a
-***[h]*"a
**a*a*