Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/specs/new/em_strong_unclosed_orphan.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>**a<em>b</em>c</p>
1 change: 1 addition & 0 deletions test/specs/new/em_strong_unclosed_orphan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**a*b*c