From cb39da8c5beddabf062299e89bdea872bcafd182 Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Tue, 18 Feb 2020 15:16:53 +0900 Subject: [PATCH 1/2] Fix fenced code blocks in Markdown lexer --- lib/rouge/lexers/markdown.rb | 8 +++++--- spec/visual/samples/markdown | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/rouge/lexers/markdown.rb b/lib/rouge/lexers/markdown.rb index 4feb08bc8f..b95a904100 100644 --- a/lib/rouge/lexers/markdown.rb +++ b/lib/rouge/lexers/markdown.rb @@ -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 @@ -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| diff --git a/spec/visual/samples/markdown b/spec/visual/samples/markdown index c6deaf41fc..9a2b577275 100644 --- a/spec/visual/samples/markdown +++ b/spec/visual/samples/markdown @@ -1074,3 +1074,7 @@ can't highlight me ``` json "a string": "with a triple backtick: ```" ``` + +```` console +$ hello "world" +```` From 10a0475275e50f7623f943e471c5d93335b087ea Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Tue, 18 Feb 2020 15:23:32 +0900 Subject: [PATCH 2/2] Require identical closing padding --- lib/rouge/lexers/markdown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rouge/lexers/markdown.rb b/lib/rouge/lexers/markdown.rb index b95a904100..4bfe7aac0d 100644 --- a/lib/rouge/lexers/markdown.rb +++ b/lib/rouge/lexers/markdown.rb @@ -32,7 +32,7 @@ def html rule %r/^#(?=[^#]).*?$/, Generic::Heading rule %r/^##*.*?$/, Generic::Subheading - rule %r/^([ \t]*)(`{3,}|~{3,})([^\n]*\n)((.*?)(\n)(\2))?/m do |m| + rule %r/^([ \t]*)(`{3,}|~{3,})([^\n]*\n)((.*?)(\n\1)(\2))?/m do |m| name = m[3].strip sublexer = begin