Class: Rabbit::Parser::Ext::CodeRay::RabbitEncoder

Inherits:
CodeRay::Encoders::Encoder
  • Object
show all
Includes:
Element
Defined in:
lib/rabbit/parser/ext/coderay.rb

Instance Method Summary collapse

Instance Method Details

#begin_line(kind) ⇒ Object



42
43
44
45
# File 'lib/rabbit/parser/ext/coderay.rb', line 42

def begin_line(kind)
  p [:begin_line, kind] if Utils.syntax_highlighting_debug?
  nil
end

#close_token(kind) ⇒ Object



52
53
54
55
56
57
# File 'lib/rabbit/parser/ext/coderay.rb', line 52

def close_token(kind)
  p [:close, kind] if Utils.syntax_highlighting_debug?
  block = @elements.pop
  @out = @elements.last
  block
end

#end_line(kind) ⇒ Object



47
48
49
50
# File 'lib/rabbit/parser/ext/coderay.rb', line 47

def end_line(kind)
  p [:end_line, kind] if Utils.syntax_highlighting_debug?
  nil
end

#finish(options) ⇒ Object



59
60
61
# File 'lib/rabbit/parser/ext/coderay.rb', line 59

def finish(options)
  super
end

#open_token(kind) ⇒ Object



35
36
37
38
39
40
# File 'lib/rabbit/parser/ext/coderay.rb', line 35

def open_token(kind)
  p [:open, kind] if Utils.syntax_highlighting_debug?
  @out = TextContainer.new
  @elements << @out
  CustomTag.new("syntax-#{kind}")
end

#setup(options) ⇒ Object



21
22
23
24
25
# File 'lib/rabbit/parser/ext/coderay.rb', line 21

def setup(options)
  super
  @out = SyntaxHighlightingBlock.new
  @elements = [@out]
end

#text_token(text, type = :plain) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/rabbit/parser/ext/coderay.rb', line 27

def text_token(text, type=:plain)
  p [:text, type, text] if Utils.syntax_highlighting_debug?
  escaped_text = Escape.escape_meta_character(text)
  text_element = SyntaxHighlightingText.new(Text.new(escaped_text))
  tag_name = type.to_s.gsub(/_/, '-')
  CustomTag.new("syntax-#{tag_name}", text_element)
end