From 3ec7e55724edd25d4775513860916d0acff11c9f Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Mon, 7 Jun 2021 06:38:46 -0400 Subject: [PATCH 1/2] fix(markdown) Images with empty alt or links with empty text --- src/languages/markdown.js | 6 +++++- test/markup/markdown/links.expect.txt | 4 ++++ test/markup/markdown/links.txt | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/markup/markdown/links.expect.txt create mode 100644 test/markup/markdown/links.txt 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) From f698c604b365b6c9eace13446e971399fef6eb33 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Mon, 7 Jun 2021 06:39:55 -0400 Subject: [PATCH 2/2] pr --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index f311454d0a..c730eef085 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][] - fix(python) identifiers starting with underscore not highlighted (#3221) [Antoine Lambert][] - enh(clojure) added `edn` alias (#3213) [Stel Abrego][] - enh(elixir) much improved regular expression sigil support (#3207) [Josh Goebel][]