Class: Hylite::Pygments

Inherits:
Hyliter show all
Defined in:
lib/hylite/hyliters.rb

Instance Attribute Summary

Attributes inherited from Hyliter

#code, #lang

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hyliter

#initialize, new?

Constructor Details

This class inherits a constructor from Hylite::Hyliter

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/hylite/hyliters.rb', line 49

def self.available?
  ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir|
    File.exist? File.join(dir, 'pygmentize')
  end
end

Instance Method Details

#callObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/hylite/hyliters.rb', line 59

def call
  # From Fish, you can see all styles with:
  # for style in (pygmentize -L styles | sed -n '/\*/s/[*: ]//gp'); echo \n===== $style =====; pygmentize -f terminal256 -O style=$style -l ruby < lib/hylite.rb ; end
  out, err, status = Open3.capture3(
    'pygmentize',
    '-f', 'terminal256',
    '-O', 'style=monokai',
    '-l', lang,
    stdin_data: code
  )
  return out if status.success? && err.empty?
  raise "Uhhh, what led to this, I want to test it but don't know what can cause it / how to mimic it (and therefore what it should do)"
end

#typeObject



55
56
57
# File 'lib/hylite/hyliters.rb', line 55

def type
  :pygments
end