Skip to content

Commit

Permalink
fix(markdown) strong/emphasis requires whitespace after (#3520)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
joshgoebel and allejo authored Oct 16, 2022
1 parent 4a381cc commit 71f5cb2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/languages/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ export default function(hljs) {
contains: [], // defined later
variants: [
{
begin: /_{2}/,
begin: /_{2}(?!\s)/,
end: /_{2}/
},
{
begin: /\*{2}/,
begin: /\*{2}(?!\s)/,
end: /\*{2}/
}
]
Expand All @@ -152,11 +152,11 @@ export default function(hljs) {
contains: [], // defined later
variants: [
{
begin: /\*(?!\*)/,
begin: /\*(?![*\s])/,
end: /\*/
},
{
begin: /_(?!_)/,
begin: /_(?![_\s])/,
end: /_/,
relevance: 0
}
Expand Down
12 changes: 12 additions & 0 deletions test/markup/markdown/bold_italics.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@

<span class="hljs-strong">**<span class="hljs-emphasis">*This is bold and italic*</span>**</span>
<span class="hljs-strong">__<span class="hljs-emphasis">_This is bold and italic_</span>__</span>

** i shouldn&#x27;t be italic**

<span class="hljs-bullet">*</span> and I shouldn&#x27;t be italic either*

__ not really bold__

_ not italic_

<span class="hljs-quote">&gt; * One (this point is italic)</span>
<span class="hljs-quote">&gt; * Two</span>
<span class="hljs-quote">&gt; * Three</span>
12 changes: 12 additions & 0 deletions test/markup/markdown/bold_italics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ __Bold *then italic*__

***This is bold and italic***
___This is bold and italic___

** i shouldn't be italic**

* and I shouldn't be italic either*

__ not really bold__

_ not italic_

> * One (this point is italic)
> * Two
> * Three

0 comments on commit 71f5cb2

Please sign in to comment.