Module: Kramdown::Converter::SyntaxHighlighter::Coderay

### Home Classes Methods

### In Files

- lib/kramdown/converter/syntax_highlighter/coderay.rb

### Methods

- ::call
- ::options
- ::prepare_options

### Class/Module Index

Quicksearch

- Kramdown
- Kramdown::Converter
- Kramdown::Converter::Base
- Kramdown::Converter::Html
- Kramdown::Converter::Kramdown
- Kramdown::Converter::Latex
- Kramdown::Converter::MathEngine
- Kramdown::Converter::MathEngine::Itex2MML
- Kramdown::Converter::MathEngine::Mathjax
- Kramdown::Converter::MathEngine::Ritex
- Kramdown::Converter::RemoveHtmlTags
- Kramdown::Converter::SyntaxHighlighter
- Kramdown::Converter::SyntaxHighlighter::Coderay
- Kramdown::Converter::SyntaxHighlighter::Rouge
- Kramdown::Converter::Toc
- Kramdown::Document
- Kramdown::Element
- Kramdown::Error
- Kramdown::Options
- Kramdown::Options::Boolean
- Kramdown::Parser
- Kramdown::Parser::Base
- Kramdown::Parser::GFM
- Kramdown::Parser::Html
- Kramdown::Parser::Html::Constants
- Kramdown::Parser::Html::ElementConverter
- Kramdown::Parser::Html::Parser
- Kramdown::Parser::Kramdown
- Kramdown::Parser::Markdown
- Kramdown::Utils
- Kramdown::Utils::Configurable
- Kramdown::Utils::Entities
- Kramdown::Utils::Entities::Entity
- Kramdown::Utils::Html
- Kramdown::Utils::OrderedHash
- Kramdown::Utils::StringScanner
- Kramdown::Utils::Unidecoder

No matching classes.

# Kramdown::Converter::SyntaxHighlighter::Coderay

Uses Coderay to highlight code blocks and code spans.

### Constants

AVAILABLE

  Highlighting via coderay 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/coderay.rb, line 23
    def self.call(converter, text, lang, type, _unused_opts)
      return nil unless converter.options[:enable_coderay]

      if type == :span && lang
        ::CodeRay.scan(text, lang.to_sym).html(options(converter, :span)).chomp
      elsif type == :block && (lang || options(converter, :default_lang))
        lang = (lang || options(converter, :default_lang)).to_sym
        ::CodeRay.scan(text, lang).html(options(converter, :block)).chomp << "\n"
      else
        nil
      end
    end

options(converter, type) click to toggle source

    # File lib/kramdown/converter/syntax_highlighter/coderay.rb, line 36
    def self.options(converter, type)
      prepare_options(converter)
      converter.data[:syntax_highlighter_coderay][type]
    end

prepare_options(converter) click to toggle source

    # File lib/kramdown/converter/syntax_highlighter/coderay.rb, line 41
    def self.prepare_options(converter)
      return if converter.data.key?(:syntax_highlighter_coderay)

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

      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[:default_lang] = converter.options[:coderay_default_lang] || opts.delete(:default_lang)
      cache[:span] = {
        :css => converter.options[:coderay_css]
      }.update(opts).update(span_opts).update(:wrap => :span)
      cache[:block] = {
        :wrap => converter.options[:coderay_wrap],
        :line_numbers => converter.options[:coderay_line_numbers],
        :line_number_start => converter.options[:coderay_line_number_start],
        :tab_width => converter.options[:coderay_tab_width],
        :bold_every => converter.options[:coderay_bold_every],
        :css => converter.options[:coderay_css]
      }.update(opts).update(block_opts)

      [:css, :wrap, :line_numbers].each do |key|
        [:block, :span].each do |type|
          cache[type][key] = cache[type][key].to_sym if cache[type][key].kind_of?(String)
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.