Skip to content
This repository
Browse code

Wrap CodeRay into <code>

  • Loading branch information...
commit 39c2b9454877135abfec1728147363efdc75ff87 1 parent f203902
Nando Vieira authored August 15, 2012
8  lib/kitabu/syntax/highlight.rb
@@ -15,7 +15,13 @@ def self.pygments(code, language)
15 15
       end
16 16
 
17 17
       def self.coderay(code, language)
18  
-        CodeRay.scan(code, language).div(:css => :class)
  18
+        html = Nokogiri::HTML(CodeRay.scan(code, language).div(:css => :class))
  19
+        coderay = html.css("div.CodeRay").first
  20
+        coderay.set_attribute "class", "CodeRay #{language}"
  21
+        pre = html.css("pre").first
  22
+        pre.replace Nokogiri.make("<pre><code>#{pre.inner_html}</code></pre>")
  23
+
  24
+        coderay.to_xhtml
19 25
       end
20 26
     end
21 27
   end
8  spec/kitabu/syntax_spec.rb
@@ -81,10 +81,18 @@ def hello(name)
81 81
     Kitabu::Syntax.render(root, :markdown, "@@@ ruby code.rb @@@").should have_tag("div.CodeRay", 1)
82 82
   end
83 83
 
  84
+  it "adds language class" do
  85
+    Kitabu::Syntax.render(root, :markdown, "@@@ ruby code.rb @@@").should have_tag("div.CodeRay.ruby", 1)
  86
+  end
  87
+
84 88
   it "wraps code in pre tag" do
85 89
     Kitabu::Syntax.render(root, :markdown, "@@@ ruby code.rb @@@").should have_tag("pre", 1)
86 90
   end
87 91
 
  92
+  it "wraps source in code tag" do
  93
+    Kitabu::Syntax.render(root, :markdown, "@@@ ruby code.rb @@@").should have_tag("pre > code", 1)
  94
+  end
  95
+
88 96
   it "wraps code in notextile tag" do
89 97
     Kitabu::Syntax.render(root, :textile, "@@@ ruby code.rb @@@").should have_tag("notextile", 1)
90 98
   end

0 notes on commit 39c2b94

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