diff --git a/lib/rouge/lexers/markdown.rb b/lib/rouge/lexers/markdown.rb index 4bfe7aac0d..a0e5fd0176 100644 --- a/lib/rouge/lexers/markdown.rb +++ b/lib/rouge/lexers/markdown.rb @@ -102,7 +102,7 @@ def html end # links and images - rule %r/(!?\[)(#{edot}*?)(\])/ do + rule %r/(!?\[)(#{edot}*?)(\])(?=[\[(])/ do groups Punctuation, Name::Variable, Punctuation push :link end @@ -117,7 +117,6 @@ def html rule %r/<.*?@.+[.].+>/, Name::Variable rule %r[<(https?|mailto|ftp)://#{edot}*?>], Name::Variable - rule %r/[^\\`\[*\n&<]+/, Text # inline html @@ -125,6 +124,9 @@ def html rule(/<#{edot}*?>/) { delegate html } rule %r/[&<]/, Text + # An opening square bracket that is not a link + rule %r/\[/, Text + rule %r/\n/, Text end diff --git a/spec/visual/samples/markdown b/spec/visual/samples/markdown index 9a2b577275..42f992e900 100644 --- a/spec/visual/samples/markdown +++ b/spec/visual/samples/markdown @@ -1078,3 +1078,16 @@ can't highlight me ```` console $ hello "world" ```` + +````markdown +Here is an example of [feature](../feature.md): + +```console +$ echo "Sample feature output" +``` +```` + +[This is a link `with backticks`](example.com) +[This is a link to a TOML section `[with brackets]` (and backticks)](example.com) +[This is a link to a TOML section `[[with double brackets]]` (and backticks)](example.com) +[This is not a link `with backticks`] (example.com)