Module: Kramdown::Converter::SyntaxHighlighter::Coderay
- Defined in:
- lib/kramdown/converter/syntax_highlighter/coderay.rb
Overview
Uses Coderay to highlight code blocks and code spans.
Class Method Summary collapse
- .call(converter, text, lang, type, _unused_opts) ⇒ Object
- .options(converter, type) ⇒ Object
- .prepare_options(converter) ⇒ Object
Class Method Details
.call(converter, text, lang, type, _unused_opts) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kramdown/converter/syntax_highlighter/coderay.rb', line 24 def self.call(converter, text, lang, type, _unused_opts) return nil unless converter.[:enable_coderay] if type == :span && lang ::CodeRay.scan(text, lang.to_sym).html((converter, :span)).chomp elsif type == :block && (lang || (converter, :default_lang)) lang = (lang || (converter, :default_lang)).to_s.gsub(/-/, '_').to_sym ::CodeRay.scan(text, lang).html((converter, :block)).chomp << "\n" else nil end end |
.options(converter, type) ⇒ Object
37 38 39 40 |
# File 'lib/kramdown/converter/syntax_highlighter/coderay.rb', line 37 def self.(converter, type) (converter) converter.data[:syntax_highlighter_coderay][type] end |
.prepare_options(converter) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kramdown/converter/syntax_highlighter/coderay.rb', line 42 def self.(converter) return if converter.data.key?(:syntax_highlighter_coderay) cache = converter.data[:syntax_highlighter_coderay] = {} opts = converter.[: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.[:coderay_default_lang] || opts.delete(:default_lang) cache[:span] = { :css => converter.[:coderay_css] }.update(opts).update(span_opts).update(:wrap => :span) cache[:block] = { :wrap => converter.[:coderay_wrap], :line_numbers => converter.[:coderay_line_numbers], :line_number_start => converter.[:coderay_line_number_start], :tab_width => converter.[:coderay_tab_width], :bold_every => converter.[:coderay_bold_every], :css => converter.[: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 |