Class: Nanoc::Filters::ColorizeSyntax::Colorizers::SimonHighlightColorizer 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.

Constant Summary collapse

SIMON_HIGHLIGHT_OPT_MAP =

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

{
  wrap: '-W',
  include_style: '-I',
  line_numbers: '-l',
}.freeze

Instance Method Summary collapse

Methods inherited from Abstract

#postprocess

Instance Method Details

#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.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/nanoc/filters/colorize_syntax/colorizers.rb', line 97

def process(code, language, params = {})
  check_availability('highlight', '--version')

  cmd = ['highlight', '--syntax', language, '--fragment']
  params.each_key do |key|
    if SIMON_HIGHLIGHT_OPT_MAP[key]
      cmd << SIMON_HIGHLIGHT_OPT_MAP[key]
    else
      # TODO: allow passing other options
      case key
      when :style
        cmd << '--style' << params[:style]
      end
    end
  end

  TTY::Command.new(printer: :null).run(*cmd, input: code).out
end