Skip to content

Commit

Permalink
ensure pygmentize output is markdown compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Mar 6, 2011
1 parent 0c70cd5 commit 09b8091
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/albino.rb
Expand Up @@ -79,7 +79,10 @@ def execute(options = {})
end end


def colorize(options = {}) 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 end
alias_method :to_s, :colorize alias_method :to_s, :colorize


Expand Down
3 changes: 3 additions & 0 deletions lib/albino/multi.rb
Expand Up @@ -82,8 +82,11 @@ def colorize(options = {})


memo << code << SEPARATOR memo << code << SEPARATOR
end.join("") end.join("")

child = Child.new(self.class.bin, options) child = Child.new(self.class.bin, options)
pieces = child.out.split(SEPARATOR) 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 @multi ? pieces : pieces.first
end end


Expand Down
5 changes: 5 additions & 0 deletions test/albino_test.rb
Expand Up @@ -25,6 +25,11 @@ def test_accepts_non_alpha_options
assert_equal '', @syntaxer.colorize(:f => 'html+c#-dump') assert_equal '', @syntaxer.colorize(:f => 'html+c#-dump')
end 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 def test_works_with_strings
syntaxer = Albino.new("class New\nend", :ruby) syntaxer = Albino.new("class New\nend", :ruby)
assert_match %r(highlight), code=syntaxer.colorize assert_match %r(highlight), code=syntaxer.colorize
Expand Down
5 changes: 5 additions & 0 deletions test/multi_albino_test.rb
Expand Up @@ -15,6 +15,11 @@ def test_defaults_to_text
assert_no_match regex, syntaxer.colorize assert_no_match regex, syntaxer.colorize
end 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 def test_works_with_strings
syntaxer = Albino::Multi.new("class New\nend", :ruby) syntaxer = Albino::Multi.new("class New\nend", :ruby)
assert_match %r(highlight), code=syntaxer.colorize assert_match %r(highlight), code=syntaxer.colorize
Expand Down

0 comments on commit 09b8091

Please sign in to comment.