Sha256: 56c804286829f3c0249eab6ef8733848e6adb5742fd7152ff7c8d542dc06fc02

Contents?: true

Size: 554 Bytes

Versions: 5

Compression:

Stored size: 554 Bytes

Contents

# frozen_string_literal: true

module Kitabu
  class Syntax
    class Highlight
      def self.apply(code, language)
        coderay(code, language)
      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

5 entries across 5 versions & 1 rubygems

Version Path
kitabu-3.1.0 lib/kitabu/syntax/highlight.rb
kitabu-3.0.3 lib/kitabu/syntax/highlight.rb
kitabu-3.0.2 lib/kitabu/syntax/highlight.rb
kitabu-3.0.1 lib/kitabu/syntax/highlight.rb
kitabu-3.0.0 lib/kitabu/syntax/highlight.rb