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

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.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/nanoc/filters/colorize_syntax/colorizers.rb', line 60

def process(code, language, params = {})
  check_availability('pygmentize', '-V')

  params[:encoding] ||= 'utf-8'
  params[:nowrap] ||= 'True'

  cmd = ['pygmentize', '-l', language, '-f', 'html']
  cmd << '-O' << params.map { |k, v| "#{k}=#{v}" }.join(',') unless params.empty?

  stdout = StringIO.new
  stderr = $stderr
  piper = Nanoc::Extra::Piper.new(stdout: stdout, stderr: stderr)
  piper.run(cmd, code)

  stdout.string
end