Skip to content

Commit

Permalink
Allow [+.#-] in highlight lang shortnames. Fixes jekyll#282.
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Jan 16, 2012
1 parent 4fe5e6b commit c14eb34
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
2 changes: 2 additions & 0 deletions History.txt
Expand Up @@ -2,6 +2,8 @@
* Minor Enhancements
* Add ability to explicitly specify included files (#261)
* Add --default-mimetype option (#279)
* Bug Fixes
* Allow some special characters in highlight names

== 0.11.2 / 2011-12-27
* Bug Fixes
Expand Down
15 changes: 10 additions & 5 deletions lib/jekyll/tags/highlight.rb
Expand Up @@ -3,14 +3,19 @@ module Jekyll
class HighlightBlock < Liquid::Block
include Liquid::StandardFilters

# We need a language, but the linenos argument is optional.
SYNTAX = /(\w+)\s?([\w\s=]+)*/
# 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:
#
# 1. name
# 2. name=value
SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=\w+)?)*)$/

def initialize(tag_name, markup, tokens)
super
if markup =~ SYNTAX
if markup.strip =~ SYNTAX
@lang = $1
if defined? $2
if defined?($2) && $2 != ''
tmp_options = {}
$2.split.each do |opt|
key, value = opt.split('=')
Expand All @@ -23,7 +28,7 @@ def initialize(tag_name, markup, tokens)
end
tmp_options[key] = value
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
@options = { 'O' => tmp_options.join(',') }
else
Expand Down
35 changes: 35 additions & 0 deletions test/test_tags.rb
Expand Up @@ -31,6 +31,41 @@ def fill_post(code, override = {})
create_post(content, override)
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
setup do
fill_post("test")
Expand Down

0 comments on commit c14eb34

Please sign in to comment.