Merge pull request #2532 from alexmedearis/hl_lines

This commit is contained in:
Parker Moore 2014-06-25 16:14:14 -04:00
commit cedbdf43ca
2 changed files with 19 additions and 5 deletions

View File

@ -4,9 +4,11 @@ module Jekyll
include Liquid::StandardFilters include Liquid::StandardFilters
# The regular expression syntax checker. Start with the language specifier. # The regular expression syntax checker. Start with the language specifier.
# Follow that by zero or more space separated options that take one of two # Follow that by zero or more space separated options that take one of three
# forms: name or name=value # forms: name, name=value, or name="<quoted list>"
SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=\w+)?)*)$/ #
# <quoted list> 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) def initialize(tag_name, markup, tokens)
super super
@ -14,8 +16,14 @@ module Jekyll
@lang = $1.downcase @lang = $1.downcase
@options = {} @options = {}
if defined?($2) && $2 != '' if defined?($2) && $2 != ''
$2.split.each do |opt| # Split along 3 possible forms -- key="<quoted list>", key=value, or key
$2.scan(/(?:\w="[^"]*"|\w=\w|\w)+/) do |opt|
key, value = opt.split('=') key, value = opt.split('=')
# If a quoted list, convert to array
if value && value.include?("\"")
value.gsub!(/"/, "")
value = value.split
end
@options[key.to_sym] = value || true @options[key.to_sym] = value || true
end end
end end

View File

@ -76,6 +76,12 @@ CONTENT
tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl', ["test", "{% endhighlight %}", "\n"]) 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)) 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 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"]) tag = Jekyll::Tags::HighlightBlock.new('highlight', 'Ruby ', ["test", "{% endhighlight %}", "\n"])
assert_equal "ruby", tag.instance_variable_get(:@lang), "lexers should be case insensitive" assert_equal "ruby", tag.instance_variable_get(:@lang), "lexers should be case insensitive"
end end