Class: Gorgyrella::Formatters::Ultraviolet

Inherits:
Object
  • Object
show all
Defined in:
lib/gorgyrella/formatters/ultraviolet.rb

Class Method Summary collapse

Class Method Details

.highlight(text, lexer, format, line_numbers = true, theme = 'amy') ⇒ Object

Will silently ignore unknown lexers, will raise an error if unknown format called.



8
9
10
11
# File 'lib/gorgyrella/formatters/ultraviolet.rb', line 8

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

.resolve_format(format, parent_filename = nil, first_line = 0) ⇒ Object



27
28
29
30
31
32
# File 'lib/gorgyrella/formatters/ultraviolet.rb', line 27

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

.resolve_lexer(file, language = nil, sample_text = "") ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gorgyrella/formatters/ultraviolet.rb', line 13

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