Skip to content
Browse files

ensure pygmentize output is markdown compatible

  • Loading branch information...
1 parent 0c70cd5 commit 09b80918bf94da575288c1649fa0411ff2515041 @tmm1 tmm1 committed Mar 5, 2011
Showing with 17 additions and 1 deletion.
  1. +4 −1 lib/albino.rb
  2. +3 −0 lib/albino/multi.rb
  3. +5 −0 test/albino_test.rb
  4. +5 −0 test/multi_albino_test.rb
View
5 lib/albino.rb
@@ -79,7 +79,10 @@ def execute(options = {})
end
def colorize(options = {})
- execute(options).out
+ out = execute(options).out
+ # markdown requires block elements on their own line
+ out.sub!(%r{</pre></div>\Z}, "</pre>\n</div>")
+ out
end
alias_method :to_s, :colorize
View
3 lib/albino/multi.rb
@@ -82,8 +82,11 @@ def colorize(options = {})
memo << code << SEPARATOR
end.join("")
+
child = Child.new(self.class.bin, options)
pieces = child.out.split(SEPARATOR)
+ # markdown requires block elements on their own line
+ pieces.each{ |code| code.sub!(%r{</pre></div>\Z}, "</pre>\n</div>") }
@multi ? pieces : pieces.first
end
View
5 test/albino_test.rb
@@ -25,6 +25,11 @@ def test_accepts_non_alpha_options
assert_equal '', @syntaxer.colorize(:f => 'html+c#-dump')
end
+ def test_markdown_compatible
+ code = Albino.colorize('1+2', :ruby)
+ assert_no_match %r{</pre></div>\Z}, code
+ end
+
def test_works_with_strings
syntaxer = Albino.new("class New\nend", :ruby)
assert_match %r(highlight), code=syntaxer.colorize
View
5 test/multi_albino_test.rb
@@ -15,6 +15,11 @@ def test_defaults_to_text
assert_no_match regex, syntaxer.colorize
end
+ def test_markdown_compatible
+ code = Albino::Multi.colorize('1+2', :ruby)
+ assert_no_match %r{</pre></div>\Z}, code
+ end
+
def test_works_with_strings
syntaxer = Albino::Multi.new("class New\nend", :ruby)
assert_match %r(highlight), code=syntaxer.colorize

0 comments on commit 09b8091

Please sign in to comment.
Something went wrong with that request. Please try again.