From f9bc93b2bbcbecd15bf8a838dc47fe38b9392f69 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 19 Nov 2020 08:30:40 -0600 Subject: [PATCH] fix: fix em and strong starting with special char (#1832) --- src/Lexer.js | 8 +++++++- test/specs/new/em_after_inline.html | 15 +++++++++++++++ test/specs/new/em_after_inline.md | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/specs/new/em_after_inline.html create mode 100644 test/specs/new/em_after_inline.md diff --git a/src/Lexer.js b/src/Lexer.js index 27a740cee0..493ce9e6ea 100644 --- a/src/Lexer.js +++ b/src/Lexer.js @@ -328,12 +328,13 @@ module.exports = class Lexer { /** * Lexing/Compiling */ - inlineTokens(src, tokens = [], inLink = false, inRawBlock = false, prevChar = '') { + inlineTokens(src, tokens = [], inLink = false, inRawBlock = false) { let token; // String with links masked to avoid interference with em and strong let maskedSrc = src; let match; + let keepPrevChar, prevChar; // Mask out reflinks if (this.tokens.links) { @@ -352,6 +353,10 @@ module.exports = class Lexer { } while (src) { + if (!keepPrevChar) { + prevChar = ''; + } + keepPrevChar = false; // escape if (token = this.tokenizer.escape(src)) { src = src.substring(token.raw.length); @@ -444,6 +449,7 @@ module.exports = class Lexer { if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) { src = src.substring(token.raw.length); prevChar = token.raw.slice(-1); + keepPrevChar = true; tokens.push(token); continue; } diff --git a/test/specs/new/em_after_inline.html b/test/specs/new/em_after_inline.html new file mode 100644 index 0000000000..4762374d7e --- /dev/null +++ b/test/specs/new/em_after_inline.html @@ -0,0 +1,15 @@ +

a
@

+ +

aaa@

+ +

aaa@

+ +

aa@

+ +

aa@

+ +

ahttp://a.com@

+ +

aa@

+ +

a@

diff --git a/test/specs/new/em_after_inline.md b/test/specs/new/em_after_inline.md new file mode 100644 index 0000000000..7daefcd8d7 --- /dev/null +++ b/test/specs/new/em_after_inline.md @@ -0,0 +1,16 @@ +a\ +*@* + +a*a*_a_*@* + +a**a**_a_*@* + +a~a~*@* + +a`a`*@* + +a*@* + +a[a](a)*@* + +a*@*