Class: CodeRay::Encoders::XML

Inherits:
Encoder
  • Object
show all
Defined in:
lib/coderay/encoders/xml.rb

Overview

XML Encoder

Uses REXML. Very slow.

Constant Summary collapse

FILE_EXTENSION =
'xml'
DEFAULT_OPTIONS =
{
  :tab_width => 8,
  :pretty => -1,
  :transitive => false,
}

Instance Attribute Summary

Attributes inherited from Encoder

#options, #scanner

Attributes included from Plugin

#plugin_id

Instance Method Summary collapse

Methods inherited from Encoder

#<<, #begin_line, const_missing, #encode, #encode_tokens, #end_line, file_extension, #file_extension, #initialize, #token

Methods included from Plugin

#aliases, #plugin_host, #register_for, #title

Constructor Details

This class inherits a constructor from CodeRay::Encoders::Encoder

Instance Method Details

#begin_group(kind) ⇒ Object



58
59
60
# File 'lib/coderay/encoders/xml.rb', line 58

def begin_group kind
  @node = @node.add_element kind.to_s
end

#end_group(kind) ⇒ Object



62
63
64
65
66
67
# File 'lib/coderay/encoders/xml.rb', line 62

def end_group kind
  if @node == @root
    raise 'no token to close!'
  end
  @node = @node.parent
end

#text_token(text, kind) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/coderay/encoders/xml.rb', line 38

def text_token text, kind
  if kind == :space
    token = @node
  else
    token = @node.add_element kind.to_s
  end
  text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl|
    case
    when space
      token << REXML::Text.new(space, true)
    when tab
      token << REXML::Text.new(tab, true)
    when nl
      token << REXML::Text.new(nl, true)
    else
      token << REXML::Text.new($&)
    end
  end
end