Sha256: 36719f5dabe4342bbf5f011d089ced0703604f785a45482ed62f3e5f3d87fdce

Contents?: true

Size: 722 Bytes

Versions: 9

Compression:

Stored size: 722 Bytes

Contents

require 'rouge'

module Jazzy
  # This module helps highlight code
  module Highlighter
    SWIFT = 'swift'.freeze
    OBJC = 'objective_c'.freeze

    class Formatter < Rouge::Formatters::HTML
      def initialize(language)
        @language = language
        super()
      end

      def stream(tokens, &b)
        yield "<pre class=\"highlight #{@language}\"><code>"
        super
        yield "</code></pre>\n"
      end
    end

    def self.highlight_swift(source)
      highlight(source, SWIFT)
    end

    def self.highlight_objc(source)
      highlight(source, OBJC)
    end

    def self.highlight(source, language)
      source && Rouge.highlight(source, language, Formatter.new(language))
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
jazzy-0.13.7 lib/jazzy/highlighter.rb
jazzy-0.13.6 lib/jazzy/highlighter.rb
jazzy-0.13.5 lib/jazzy/highlighter.rb
jazzy-0.13.4 lib/jazzy/highlighter.rb
jazzy-0.13.3 lib/jazzy/highlighter.rb
jazzy-0.13.2 lib/jazzy/highlighter.rb
jazzy-0.13.1 lib/jazzy/highlighter.rb
jazzy-0.13.0 lib/jazzy/highlighter.rb
jazzy-0.12.0 lib/jazzy/highlighter.rb