From 8b860d3f0eba4fd0ceb546ad73956d2628214ad3 Mon Sep 17 00:00:00 2001 From: Alex Medearis Date: Wed, 18 Jun 2014 17:08:50 -0700 Subject: [PATCH 1/4] Fixes highlight.rb to correctly parse list values --- lib/jekyll/tags/highlight.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 29a6ea0a..7c77f6ba 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -4,9 +4,11 @@ module Jekyll include Liquid::StandardFilters # The regular expression syntax checker. Start with the language specifier. - # Follow that by zero or more space separated options that take one of two - # forms: name or name=value - SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=\w+)?)*)$/ + # Follow that by zero or more space separated options that take one of three + # forms: name, name=value, or name="" + # + # is a space-separated list of numbers + SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=(\w+|"([0-9]\s)*[0-9]"))?)*)$/ def initialize(tag_name, markup, tokens) super @@ -14,8 +16,14 @@ module Jekyll @lang = $1.downcase @options = {} if defined?($2) && $2 != '' - $2.split.each do |opt| + # Split along 3 possible forms -- key="", key=value, or key + $2.scan(/(?:\w="[^"]*"|\w=\w|\w)+/) do |opt| key, value = opt.split('=') + # If a quoted list, convert to array + if value and value.include? "\"" + value.gsub!(/"/, "") + value = value.split + end @options[key.to_sym] = value || true end end From 674b540c6f3b4cde3052a76a149cf91f54ed8890 Mon Sep 17 00:00:00 2001 From: Alex Medearis Date: Wed, 18 Jun 2014 17:27:27 -0700 Subject: [PATCH 2/4] unit tests --- lib/jekyll/tags/highlight.rb | 2 +- test/test_tags.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 7c77f6ba..15354308 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -20,7 +20,7 @@ module Jekyll $2.scan(/(?:\w="[^"]*"|\w=\w|\w)+/) do |opt| key, value = opt.split('=') # If a quoted list, convert to array - if value and value.include? "\"" + if value && value.include?("\"") value.gsub!(/"/, "") value = value.split end diff --git a/test/test_tags.rb b/test/test_tags.rb index 7f2dd4d5..129042dc 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -75,7 +75,13 @@ CONTENT tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl', ["test", "{% endhighlight %}", "\n"]) assert_equal({ :cssclass => 'hl', :linenos => 'table' }, tag.instance_variable_get(:@options)) - + + tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos=3', ["test", "{% endhighlight %}", "\n"]) + assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => '3' }, tag.instance_variable_get(:@options)) + + tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl ="3 5 6"', ["test", "{% endhighlight %}", "\n"]) + assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => ['3', '5', '6'] }, tag.instance_variable_get(:@options)) + tag = Jekyll::Tags::HighlightBlock.new('highlight', 'Ruby ', ["test", "{% endhighlight %}", "\n"]) assert_equal "ruby", tag.instance_variable_get(:@lang), "lexers should be case insensitive" end From a7d20df95aab9191d06c2c8b5d218c7c99f2f682 Mon Sep 17 00:00:00 2001 From: Alex Medearis Date: Wed, 18 Jun 2014 17:29:07 -0700 Subject: [PATCH 3/4] unit tests --- test/test_tags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_tags.rb b/test/test_tags.rb index 129042dc..3347cc7c 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -79,7 +79,7 @@ CONTENT tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos=3', ["test", "{% endhighlight %}", "\n"]) assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => '3' }, tag.instance_variable_get(:@options)) - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl ="3 5 6"', ["test", "{% endhighlight %}", "\n"]) + tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos="3 5 6"', ["test", "{% endhighlight %}", "\n"]) assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => ['3', '5', '6'] }, tag.instance_variable_get(:@options)) tag = Jekyll::Tags::HighlightBlock.new('highlight', 'Ruby ', ["test", "{% endhighlight %}", "\n"]) From b202b508f2d7084700bfc9b39e2fcdd0259a889b Mon Sep 17 00:00:00 2001 From: Alex Medearis Date: Wed, 18 Jun 2014 17:48:50 -0700 Subject: [PATCH 4/4] handles line numbers with more than 1 digit --- lib/jekyll/tags/highlight.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 15354308..34b76387 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -8,7 +8,7 @@ module Jekyll # forms: name, name=value, or name="" # # is a space-separated list of numbers - SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=(\w+|"([0-9]\s)*[0-9]"))?)*)$/ + SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+"))?)*)$/ def initialize(tag_name, markup, tokens) super