mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: an unmatched strong run before emphasis stays literal (#4008)
This commit is contained in:
+11
-1
@@ -746,7 +746,12 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
|
||||
const lLength = [...match[0]].length - 1;
|
||||
let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
|
||||
|
||||
const endReg = match[0][0] === '*' ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
||||
const delimChar = match[0][0];
|
||||
// A mid-run opener (for example the second star of an unmatched `**`) must
|
||||
// only pair with a delimiter that can only close, otherwise it steals the
|
||||
// opener of a later span (`**a*b*c` must be `**a<em>b</em>c`).
|
||||
const midRun = prevChar === delimChar;
|
||||
const endReg = delimChar === '*' ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
||||
endReg.lastIndex = 0;
|
||||
|
||||
// Clip maskedSrc to same section of string as src (move to lexer?)
|
||||
@@ -767,6 +772,11 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
|
||||
midDelimTotal += rLength;
|
||||
continue; // CommonMark Emphasis Rules 9-10
|
||||
}
|
||||
if (midRun) {
|
||||
// A mid-run opener cannot close against an ambiguous delimiter that
|
||||
// can also open; that delimiter opens its own emphasis span instead.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delimTotal -= rLength;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<p>**a<em>b</em>c</p>
|
||||
@@ -0,0 +1 @@
|
||||
**a*b*c
|
||||
Reference in New Issue
Block a user