Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Wrap CodeRay into <code>

  • Loading branch information...
commit 39c2b9454877135abfec1728147363efdc75ff87 1 parent f203902
@fnando authored
Showing with 15 additions and 1 deletion.
  1. +7 −1 lib/kitabu/syntax/highlight.rb
  2. +8 −0 spec/kitabu/syntax_spec.rb
View
8 lib/kitabu/syntax/highlight.rb
@@ -15,7 +15,13 @@ def self.pygments(code, language)
end
def self.coderay(code, language)
- CodeRay.scan(code, language).div(:css => :class)
+ html = Nokogiri::HTML(CodeRay.scan(code, language).div(:css => :class))
+ coderay = html.css("div.CodeRay").first
+ coderay.set_attribute "class", "CodeRay #{language}"
+ pre = html.css("pre").first
+ pre.replace Nokogiri.make("<pre><code>#{pre.inner_html}</code></pre>")
+
+ coderay.to_xhtml
end
end
end
View
8 spec/kitabu/syntax_spec.rb
@@ -81,10 +81,18 @@ def hello(name)
Kitabu::Syntax.render(root, :markdown, "@@@ ruby code.rb @@@").should have_tag("div.CodeRay", 1)
end
+ it "adds language class" do
+ Kitabu::Syntax.render(root, :markdown, "@@@ ruby code.rb @@@").should have_tag("div.CodeRay.ruby", 1)
+ end
+
it "wraps code in pre tag" do
Kitabu::Syntax.render(root, :markdown, "@@@ ruby code.rb @@@").should have_tag("pre", 1)
end
+ it "wraps source in code tag" do
+ Kitabu::Syntax.render(root, :markdown, "@@@ ruby code.rb @@@").should have_tag("pre > code", 1)
+ end
+
it "wraps code in notextile tag" do
Kitabu::Syntax.render(root, :textile, "@@@ ruby code.rb @@@").should have_tag("notextile", 1)
end
Please sign in to comment.
Something went wrong with that request. Please try again.