Sha256: 03d111ba7206b00d62043fc206c86819f8a0ec207c30a885738a19ea400df6ac
Contents?: true
Size: 777 Bytes
Versions: 14
Compression:
Stored size: 777 Bytes
Contents
module Kitabu class Syntax class Highlight def self.apply(code, language) if Dependency.pygments_rb? pygments(code, language) else coderay(code, language) end end private def self.pygments(code, language) Pygments.highlight(code, :lexer => language, :options => {:encoding => "utf-8"}) end 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 end end end
Version data entries
14 entries across 14 versions & 1 rubygems