Sha256: 740359ae42ecdf3dc114f28ca37d5256edaedae19a6a3b025aaedccc9aa5b7fd

Contents?: true

Size: 1.17 KB

Versions: 13

Compression:

Stored size: 1.17 KB

Contents

module Pygments
  module C
    extend self

    def start(python_path = File.expand_path('../../../vendor/pygments-main/', __FILE__))
      ENV['PYTHONPATH'], prev = python_path, ENV['PYTHONPATH']
      require 'pygments_ext'
      @started = true
    ensure
      ENV['PYTHONPATH'] = prev
    end

    def stop
    end

    def formatters
      start unless @started

      _formatters.inject(Hash.new) do |hash, (name, desc, aliases)|
        name.sub!(/Formatter$/,'')
        hash[name] = {
          :name => name,
          :description => desc,
          :aliases => aliases
        }
        hash
      end
    end

    def lexers
      start unless @started

      _lexers.inject(Hash.new) do |hash, (name, aliases, files, mimes)|
        hash[name] = {
          :description => name,
          :aliases => aliases,
          :filenames => files,
          :mimetypes => mimes
        }
        hash
      end
    end

    def highlight(code, opts={})
      start unless @started

      out = _highlight(code, opts)
      if opts[:formatter].nil? or opts[:formatter].to_s.downcase == 'html'
        out.gsub!(%r{</pre></div>\Z}, "</pre>\n</div>")
      end
      out
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pygments.rb-0.2.13 lib/pygments/c.rb
pygments.rb-0.2.12 lib/pygments/c.rb
pygments.rb-0.2.11 lib/pygments/c.rb
pygments.rb-0.2.10 lib/pygments/c.rb
pygments.rb-0.2.9 lib/pygments/c.rb
pygments.rb-0.2.8 lib/pygments/c.rb
pygments.rb-0.2.7 lib/pygments/c.rb
pygments.rb-0.2.6 lib/pygments/c.rb
pygments.rb-0.2.4 lib/pygments/c.rb
pygments.rb-0.2.3 lib/pygments/c.rb
pygments.rb-0.2.2 lib/pygments/c.rb
pygments.rb-0.2.1 lib/pygments/c.rb
pygments.rb-0.2.0 lib/pygments/c.rb