# module Kramdown::Converter::SyntaxHighlighter::Rouge

Uses Rouge which is CSS-compatible to Pygments to highlight code blocks and code spans.

### Constants

AVAILABLE

  Highlighting via Rouge is available if this constant is `true`.

### Public Class Methods

call(converter, text, lang, type, _unused_opts) click to toggle source

    # File lib/kramdown/converter/syntax_highlighter/rouge.rb, line 23
    def self.call(converter, text, lang, type, _unused_opts)
      opts = options(converter, type)
      lexer = ::Rouge::Lexer.find_fancy(lang || opts[:default_lang], text)
      return nil if opts[:disable] || !lexer

      formatter = (opts.delete(:formatter) || ::Rouge::Formatters::HTML).new(opts)
      formatter.format(lexer.lex(text))
    end

options(converter, type) click to toggle source

    # File lib/kramdown/converter/syntax_highlighter/rouge.rb, line 32
    def self.options(converter, type)
      prepare_options(converter)
      converter.data[:syntax_highlighter_rouge][type]
    end

prepare_options(converter) click to toggle source

    # File lib/kramdown/converter/syntax_highlighter/rouge.rb, line 37
    def self.prepare_options(converter)
      return if converter.data.key?(:syntax_highlighter_rouge)

      cache = converter.data[:syntax_highlighter_rouge] = {}

      opts = converter.options[:syntax_highlighter_opts].dup
      span_opts = (opts.delete(:span) || {}).dup
      block_opts = (opts.delete(:block) || {}).dup
      [span_opts, block_opts].each do |hash|
        hash.keys.each do |k|
          hash[k.kind_of?(String) ? Kramdown::Options.str_to_sym(k) : k] = hash.delete(k)
        end
      end

      cache[:span] = opts.merge(span_opts).update(:wrap => false)
      cache[:block] = opts.merge(block_opts)
    end