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 fenced code blocks in Markdown lexer #1442

Merged
merged 2 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix fenced code blocks in Markdown lexer
  • Loading branch information
pyrmont committed Feb 18, 2020
commit cb39da8c5beddabf062299e89bdea872bcafd182
8 changes: 5 additions & 3 deletions lib/rouge/lexers/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def html
rule %r/^#(?=[^#]).*?$/, Generic::Heading
rule %r/^##*.*?$/, Generic::Subheading

rule %r/^([ \t]*)(```|~~~)([^\n]*\n)((.*?)(\2))?/m do |m|
rule %r/^([ \t]*)(`{3,}|~{3,})([^\n]*\n)((.*?)(\n)(\2))?/m do |m|
name = m[3].strip
sublexer =
begin
Expand All @@ -51,8 +51,10 @@ def html
delegate sublexer, m[5]
end

if m[6]
token Punctuation, m[6]
token Text, m[6]

if m[7]
token Punctuation, m[7]
else
push do
rule %r/^([ \t]*)(#{m[2]})/ do |mb|
Expand Down
4 changes: 4 additions & 0 deletions spec/visual/samples/markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1074,3 +1074,7 @@ can't highlight me
``` json
"a string": "with a triple backtick: ```"
```

```` console
$ hello "world"
````