Last night I've done some testing on an Ubuntu installation with the same results. I've modified the Nokogiri part so it will (hopefully) work on both installations. I've used the DocumentFragment class of Nokogiri.
ruby
defsyntax_highlighter(html)
doc = Nokogiri::HTML::DocumentFragment.parse(html)
doc.css("pre[@lang]").each do |pre|
pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
end
doc.to_s
end
If I use rails c with Nokogiri::HTML("<p>content</p>").to_s
it will output: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>content</p></body></html>\n"
I'm using Nokogiri version 1.4.6, maybe it's something with the libraries Nokogiri uses?
When I give the /Library/Ruby/Gems/1.8/bin/nokogiri -v command I get:
Thanks for the screencast! When I use your example or the source code Nokogiri inserts HTML headers to the output of the syntax_highlighter method. I've fixed it by modifying the last line of that method.
ruby
defsyntax_highlighter(html)
doc = Nokogiri::HTML(html)
doc.search("//pre[@lang]").each do |pre|
pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
end
doc.at_css("body").inner_html.to_s
end
Why is it that the output in the screencast is different?
Last night I've done some testing on an Ubuntu installation with the same results. I've modified the Nokogiri part so it will (hopefully) work on both installations. I've used the DocumentFragment class of Nokogiri.
If I use
rails c
withNokogiri::HTML("<p>content</p>").to_s
it will output:
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>content</p></body></html>\n"
I'm using Nokogiri version 1.4.6, maybe it's something with the libraries Nokogiri uses?
When I give the
/Library/Ruby/Gems/1.8/bin/nokogiri -v
command I get:Hello Ryan,
Thanks for the screencast! When I use your example or the source code Nokogiri inserts HTML headers to the output of the syntax_highlighter method. I've fixed it by modifying the last line of that method.
Why is it that the output in the screencast is different?