Allow [+.#-] in highlight lang shortnames. Fixes #282.
This commit is contained in:
parent
4fe5e6ba99
commit
c14eb346a3
|
@ -2,6 +2,8 @@
|
||||||
* Minor Enhancements
|
* Minor Enhancements
|
||||||
* Add ability to explicitly specify included files (#261)
|
* Add ability to explicitly specify included files (#261)
|
||||||
* Add --default-mimetype option (#279)
|
* Add --default-mimetype option (#279)
|
||||||
|
* Bug Fixes
|
||||||
|
* Allow some special characters in highlight names
|
||||||
|
|
||||||
== 0.11.2 / 2011-12-27
|
== 0.11.2 / 2011-12-27
|
||||||
* Bug Fixes
|
* Bug Fixes
|
||||||
|
|
|
@ -3,14 +3,19 @@ module Jekyll
|
||||||
class HighlightBlock < Liquid::Block
|
class HighlightBlock < Liquid::Block
|
||||||
include Liquid::StandardFilters
|
include Liquid::StandardFilters
|
||||||
|
|
||||||
# We need a language, but the linenos argument is optional.
|
# The regular expression syntax checker. Start with the language specifier.
|
||||||
SYNTAX = /(\w+)\s?([\w\s=]+)*/
|
# Follow that by zero or more space separated options that take one of two
|
||||||
|
# forms:
|
||||||
|
#
|
||||||
|
# 1. name
|
||||||
|
# 2. name=value
|
||||||
|
SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=\w+)?)*)$/
|
||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
super
|
super
|
||||||
if markup =~ SYNTAX
|
if markup.strip =~ SYNTAX
|
||||||
@lang = $1
|
@lang = $1
|
||||||
if defined? $2
|
if defined?($2) && $2 != ''
|
||||||
tmp_options = {}
|
tmp_options = {}
|
||||||
$2.split.each do |opt|
|
$2.split.each do |opt|
|
||||||
key, value = opt.split('=')
|
key, value = opt.split('=')
|
||||||
|
@ -23,7 +28,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
tmp_options[key] = value
|
tmp_options[key] = value
|
||||||
end
|
end
|
||||||
tmp_options = tmp_options.to_a.collect { |opt| opt.join('=') }
|
tmp_options = tmp_options.to_a.sort.collect { |opt| opt.join('=') }
|
||||||
# additional options to pass to Albino
|
# additional options to pass to Albino
|
||||||
@options = { 'O' => tmp_options.join(',') }
|
@options = { 'O' => tmp_options.join(',') }
|
||||||
else
|
else
|
||||||
|
|
|
@ -31,6 +31,41 @@ CONTENT
|
||||||
create_post(content, override)
|
create_post(content, override)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "language name" do
|
||||||
|
should "match only the required set of chars" do
|
||||||
|
r = Jekyll::HighlightBlock::SYNTAX
|
||||||
|
assert_match r, "ruby"
|
||||||
|
assert_match r, "c#"
|
||||||
|
assert_match r, "xml+cheetah"
|
||||||
|
assert_match r, "x.y"
|
||||||
|
assert_match r, "coffee-script"
|
||||||
|
|
||||||
|
assert_no_match r, "blah^"
|
||||||
|
|
||||||
|
assert_match r, "ruby key=val"
|
||||||
|
assert_match r, "ruby a=b c=d"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "initialized tag" do
|
||||||
|
should "work" do
|
||||||
|
tag = Jekyll::HighlightBlock.new('highlight', 'ruby ', ["test", "{% endhighlight %}", "\n"])
|
||||||
|
assert_equal({}, tag.instance_variable_get(:@options))
|
||||||
|
|
||||||
|
tag = Jekyll::HighlightBlock.new('highlight', 'ruby linenos ', ["test", "{% endhighlight %}", "\n"])
|
||||||
|
assert_equal({'O' => "linenos=inline"}, tag.instance_variable_get(:@options))
|
||||||
|
|
||||||
|
tag = Jekyll::HighlightBlock.new('highlight', 'ruby linenos=table ', ["test", "{% endhighlight %}", "\n"])
|
||||||
|
assert_equal({'O' => "linenos=table"}, tag.instance_variable_get(:@options))
|
||||||
|
|
||||||
|
tag = Jekyll::HighlightBlock.new('highlight', 'ruby linenos=table nowrap', ["test", "{% endhighlight %}", "\n"])
|
||||||
|
assert_equal({'O' => "linenos=table,nowrap=true"}, tag.instance_variable_get(:@options))
|
||||||
|
|
||||||
|
tag = Jekyll::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl', ["test", "{% endhighlight %}", "\n"])
|
||||||
|
assert_equal({'O' => "cssclass=hl,linenos=table"}, tag.instance_variable_get(:@options))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "post content has highlight tag" do
|
context "post content has highlight tag" do
|
||||||
setup do
|
setup do
|
||||||
fill_post("test")
|
fill_post("test")
|
||||||
|
|
Loading…
Reference in New Issue