Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix brackets in links in markdown lexer #1445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/rouge/lexers/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -117,14 +117,16 @@ def html
rule %r/<.*?@.+[.].+>/, Name::Variable
rule %r[<(https?|mailto|ftp)://#{edot}*?>], Name::Variable


rule %r/[^\\`\[*\n&<]+/, Text

# inline html
rule(/&\S*;/) { delegate 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

Expand Down
13 changes: 13 additions & 0 deletions spec/visual/samples/markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)