diff --git a/src/Lexer.ts b/src/Lexer.ts index 89e291f19c..64cbe8101c 100644 --- a/src/Lexer.ts +++ b/src/Lexer.ts @@ -316,8 +316,11 @@ export class _Lexer { } } - // Mask out escaped characters - maskedSrc = maskedSrc.replace(this.tokenizer.rules.inline.anyPunctuation, '++'); + // Mask out escaped characters. + // Every mask must keep the length it replaces: emStrong and del line + // maskedSrc up with src by slicing from the end. `anyPunctuation` matches + // unicode punctuation, so an escaped astral character is 3 code units. + maskedSrc = maskedSrc.replace(this.tokenizer.rules.inline.anyPunctuation, match0 => '+'.repeat(match0.length)); // Mask out other blocks maskedSrc = maskedSrc.replace(this.tokenizer.rules.inline.blockSkip, (match0, _link, context) => { diff --git a/test/specs/new/em_escaped_astral_punctuation.html b/test/specs/new/em_escaped_astral_punctuation.html new file mode 100644 index 0000000000..588d3bab26 --- /dev/null +++ b/test/specs/new/em_escaped_astral_punctuation.html @@ -0,0 +1,7 @@ +

a\πŸ™‚

+

a \πŸ™‚ b

+

xab\πŸ™‚y

+

aa\𐄀b

+

a\πŸ™‚b

+

a\πŸ™‚

+

foo\πŸ™‚bar

diff --git a/test/specs/new/em_escaped_astral_punctuation.md b/test/specs/new/em_escaped_astral_punctuation.md new file mode 100644 index 0000000000..541830ca73 --- /dev/null +++ b/test/specs/new/em_escaped_astral_punctuation.md @@ -0,0 +1,16 @@ +--- +gfm: true +--- +*a*\πŸ™‚ + +*a* \πŸ™‚ *b* + +x*ab*\πŸ™‚y + +*a*a\𐄀*b* + +__a__\πŸ™‚b + +~~a~~\πŸ™‚ + +*foo\πŸ™‚bar*