Skip to content

Commit

Permalink
fix(markdown) Images with empty alt or links with empty text (#3233)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Jun 14, 2021
1 parent 40b6a8a commit 2dd87a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -2,6 +2,7 @@

Grammars:

- fix(markdown) Images with empty alt or links with empty text (#3233) [Josh Goebel][]
- enh(powershell) added `pwsh` alias (#3236) [tebeco][]
- fix(r) fix bug highlighting examples in doc comments [Konrad Rudolph][]
- fix(python) identifiers starting with underscore not highlighted (#3221) [Antoine Lambert][]
Expand Down
6 changes: 5 additions & 1 deletion src/languages/markdown.js
Expand Up @@ -105,12 +105,16 @@ export default function(hljs) {
},
// whatever else, lower relevance (might not be a link at all)
{
begin: /\[.+?\]\(.*?\)/,
begin: /\[.*?\]\(.*?\)/,
relevance: 0
}
],
returnBegin: true,
contains: [
{
// empty strings for alt or link text
match: /\[(?=\])/
},
{
className: 'string',
relevance: 0,
Expand Down
4 changes: 4 additions & 0 deletions test/markup/markdown/links.expect.txt
@@ -0,0 +1,4 @@
![](<span class="hljs-link">https://example.com</span>)
[](<span class="hljs-link">https://example.com</span>)
![<span class="hljs-string">alt</span>](<span class="hljs-link">https://example.com</span>)
[<span class="hljs-string">text</span>](<span class="hljs-link">https://example.com</span>)
4 changes: 4 additions & 0 deletions test/markup/markdown/links.txt
@@ -0,0 +1,4 @@
![](https://example.com)
[](https://example.com)
![alt](https://example.com)
[text](https://example.com)

0 comments on commit 2dd87a6

Please sign in to comment.