Skip to content

Commit f9bc93b

Browse files
authored
fix: fix em and strong starting with special char (#1832)
1 parent 3942e89 commit f9bc93b

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Lexer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,13 @@ module.exports = class Lexer {
328328
/**
329329
* Lexing/Compiling
330330
*/
331-
inlineTokens(src, tokens = [], inLink = false, inRawBlock = false, prevChar = '') {
331+
inlineTokens(src, tokens = [], inLink = false, inRawBlock = false) {
332332
let token;
333333

334334
// String with links masked to avoid interference with em and strong
335335
let maskedSrc = src;
336336
let match;
337+
let keepPrevChar, prevChar;
337338

338339
// Mask out reflinks
339340
if (this.tokens.links) {
@@ -352,6 +353,10 @@ module.exports = class Lexer {
352353
}
353354

354355
while (src) {
356+
if (!keepPrevChar) {
357+
prevChar = '';
358+
}
359+
keepPrevChar = false;
355360
// escape
356361
if (token = this.tokenizer.escape(src)) {
357362
src = src.substring(token.raw.length);
@@ -444,6 +449,7 @@ module.exports = class Lexer {
444449
if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
445450
src = src.substring(token.raw.length);
446451
prevChar = token.raw.slice(-1);
452+
keepPrevChar = true;
447453
tokens.push(token);
448454
continue;
449455
}

test/specs/new/em_after_inline.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<p>a<br><em>@</em></p>
2+
3+
<p>a<em>a</em><em>a</em><em>@</em></p>
4+
5+
<p>a<strong>a</strong><em>a</em><em>@</em></p>
6+
7+
<p>a<del>a</del><em>@</em></p>
8+
9+
<p>a<code>a</code><em>@</em></p>
10+
11+
<p>a<a href="http://a.com">http://a.com</a><em>@</em></p>
12+
13+
<p>a<a href="a">a</a><em>@</em></p>
14+
15+
<p>a<a><em>@</em></p>

test/specs/new/em_after_inline.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
a\
2+
*@*
3+
4+
a*a*_a_*@*
5+
6+
a**a**_a_*@*
7+
8+
a~a~*@*
9+
10+
a`a`*@*
11+
12+
a<http://a.com>*@*
13+
14+
a[a](a)*@*
15+
16+
a<a>*@*

0 commit comments

Comments
 (0)