Class: Kitabu::Syntax::Highlight
- Inherits:
-
Object
- Object
- Kitabu::Syntax::Highlight
- Defined in:
- lib/kitabu/syntax/highlight.rb
Class Method Summary collapse
Class Method Details
.apply(code, language) ⇒ Object
6 7 8 |
# File 'lib/kitabu/syntax/highlight.rb', line 6 def self.apply(code, language) coderay(code, language) end |
.coderay(code, language) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/kitabu/syntax/highlight.rb', line 10 def self.coderay(code, language) 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 |