Class: Nanoc::Filters::ColorizeSyntax::Colorizers::CoderayColorizer Private

Inherits:
Abstract
  • Object
show all
Defined in:
lib/nanoc/filters/colorize_syntax/colorizers.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#postprocess(_language, element) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nanoc/filters/colorize_syntax/colorizers.rb', line 37

def postprocess(_language, element)
  # Skip if we're a free <code>
  return if element.parent.nil?

  # <div class="code">
  div_inner = Nokogiri::XML::Node.new('div', element.document)
  div_inner['class'] = 'code'
  div_inner.children = element.dup

  # <div class="CodeRay">
  div_outer = Nokogiri::XML::Node.new('div', element.document)
  div_outer['class'] = 'CodeRay'
  div_outer.children = div_inner

  # orig element
  element.swap div_outer
end

#process(code, language, params = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
# File 'lib/nanoc/filters/colorize_syntax/colorizers.rb', line 31

def process(code, language, params = {})
  require 'coderay'

  ::CodeRay.scan(code, language).html(params)
end