Sha256: 9e248e5aca9cee323dc857ca2582b5b70b6c2886775cef2b5b387f4363fc2368

Contents?: true

Size: 962 Bytes

Versions: 2

Compression:

Stored size: 962 Bytes

Contents

require "uv"

module Gorgyrella
  module Formatters
    class Ultraviolet
      # Will silently ignore unknown lexers, will raise an error if
      # unknown format called.
      def self.highlight(text, lexer, format, line_numbers = true, theme = 'amy')
        raise "#{lexer} syntax not available" unless Uv.syntaxes.include?(lexer)
        Uv.parse( text, format, lexer, line_numbers, theme)
      end
      
      def self.resolve_lexer(file, language = nil, sample_text = "")
        if language
          language
        else
          candidates = Uv.syntax_for_file(file)
          
          if candidates.size == 1
            candidates.first[0]
          else
            nil
          end
        end
      end

      def self.resolve_format(format, parent_filename = nil, first_line = 0)
        format ||= 'xhtml'
        format = nil if format === 'text'
        format = 'xhtml' if format === 'html'
        format
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gorgyrella-0.0.1 lib/gorgyrella/formatters/ultraviolet.rb
gorgyrella-0.0.2 lib/gorgyrella/formatters/ultraviolet.rb