diff --git a/CHANGES.md b/CHANGES.md
index a3a3065e64..33e360ba9e 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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][]
diff --git a/src/languages/markdown.js b/src/languages/markdown.js
index 51bbe56f3f..a6072587a6 100644
--- a/src/languages/markdown.js
+++ b/src/languages/markdown.js
@@ -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,
diff --git a/test/markup/markdown/links.expect.txt b/test/markup/markdown/links.expect.txt
new file mode 100644
index 0000000000..6156d28198
--- /dev/null
+++ b/test/markup/markdown/links.expect.txt
@@ -0,0 +1,4 @@
+![](https://example.com)
+[](https://example.com)
+![alt](https://example.com)
+[text](https://example.com)
diff --git a/test/markup/markdown/links.txt b/test/markup/markdown/links.txt
new file mode 100644
index 0000000000..36f6c9bfa2
--- /dev/null
+++ b/test/markup/markdown/links.txt
@@ -0,0 +1,4 @@
+![](https://example.com)
+[](https://example.com)
+![alt](https://example.com)
+[text](https://example.com)