Skip to content

Commit

Permalink
fix: fix em and strong starting with special char (#1832)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Nov 19, 2020
1 parent 3942e89 commit f9bc93b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Lexer.js
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions test/specs/new/em_after_inline.html
@@ -0,0 +1,15 @@
<p>a<br><em>@</em></p>

<p>a<em>a</em><em>a</em><em>@</em></p>

<p>a<strong>a</strong><em>a</em><em>@</em></p>

<p>a<del>a</del><em>@</em></p>

<p>a<code>a</code><em>@</em></p>

<p>a<a href="http://a.com">http://a.com</a><em>@</em></p>

<p>a<a href="a">a</a><em>@</em></p>

<p>a<a><em>@</em></p>
16 changes: 16 additions & 0 deletions test/specs/new/em_after_inline.md
@@ -0,0 +1,16 @@
a\
*@*

a*a*_a_*@*

a**a**_a_*@*

a~a~*@*

a`a`*@*

a<http://a.com>*@*

a[a](a)*@*

a<a>*@*

1 comment on commit f9bc93b

@vercel
Copy link

@vercel vercel bot commented on f9bc93b Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.