Skip to content

Commit 71f5cb2

Browse files
joshgoebelallejo
andauthored
fix(markdown) strong/emphasis requires whitespace after (#3520)
* Don't let newlines exist in bold+italic for now Let's fix the immediate false positives by disallowing newlines inside of bolds and italics. And in the future, come up with a more robust expression that matches the markdown spec and can handle newlines (or whatever new APIs that may be added). Co-authored-by: Vladimir Jimenez <[email protected]>
1 parent 4a381cc commit 71f5cb2

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/languages/markdown.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ export default function(hljs) {
138138
contains: [], // defined later
139139
variants: [
140140
{
141-
begin: /_{2}/,
141+
begin: /_{2}(?!\s)/,
142142
end: /_{2}/
143143
},
144144
{
145-
begin: /\*{2}/,
145+
begin: /\*{2}(?!\s)/,
146146
end: /\*{2}/
147147
}
148148
]
@@ -152,11 +152,11 @@ export default function(hljs) {
152152
contains: [], // defined later
153153
variants: [
154154
{
155-
begin: /\*(?!\*)/,
155+
begin: /\*(?![*\s])/,
156156
end: /\*/
157157
},
158158
{
159-
begin: /_(?!_)/,
159+
begin: /_(?![_\s])/,
160160
end: /_/,
161161
relevance: 0
162162
}

test/markup/markdown/bold_italics.expect.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@
1919

2020
<span class="hljs-strong">**<span class="hljs-emphasis">*This is bold and italic*</span>**</span>
2121
<span class="hljs-strong">__<span class="hljs-emphasis">_This is bold and italic_</span>__</span>
22+
23+
** i shouldn&#x27;t be italic**
24+
25+
<span class="hljs-bullet">*</span> and I shouldn&#x27;t be italic either*
26+
27+
__ not really bold__
28+
29+
_ not italic_
30+
31+
<span class="hljs-quote">&gt; * One (this point is italic)</span>
32+
<span class="hljs-quote">&gt; * Two</span>
33+
<span class="hljs-quote">&gt; * Three</span>

test/markup/markdown/bold_italics.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ __Bold *then italic*__
1919

2020
***This is bold and italic***
2121
___This is bold and italic___
22+
23+
** i shouldn't be italic**
24+
25+
* and I shouldn't be italic either*
26+
27+
__ not really bold__
28+
29+
_ not italic_
30+
31+
> * One (this point is italic)
32+
> * Two
33+
> * Three

0 commit comments

Comments
 (0)