Sha256: 96924eb363886fe1c995258411c91ceed015b1fe12c329af70f4fedad1069dc9

Contents?: true

Size: 698 Bytes

Versions: 10

Compression:

Stored size: 698 Bytes

Contents

require 'rouge'

module Jazzy
  # This module helps highlight code
  module Highlighter
    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

    # What Rouge calls the language
    def self.default_language
      if Config.instance.objc_mode
        'objective_c'
      else
        'swift'
      end
    end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jazzy-0.11.2 lib/jazzy/highlighter.rb
jazzy-0.11.1 lib/jazzy/highlighter.rb
jazzy-0.11.0 lib/jazzy/highlighter.rb
jazzy-0.10.0 lib/jazzy/highlighter.rb
jazzy-0.9.6 lib/jazzy/highlighter.rb
jazzy-0.9.5 lib/jazzy/highlighter.rb
jazzy-0.9.4 lib/jazzy/highlighter.rb
jazzy-0.9.3 lib/jazzy/highlighter.rb
jazzy-0.9.2 lib/jazzy/highlighter.rb
jazzy-0.9.1 lib/jazzy/highlighter.rb