Class CodeRay::Encoders::XML
In: lib/coderay/encoders/xml.rb
Parent: Encoder

XML Encoder

Uses REXML. Very slow.

Methods

Constants

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

Public Instance methods

[Source]

    # File lib/coderay/encoders/xml.rb, line 58
58:     def begin_group kind
59:       @node = @node.add_element kind.to_s
60:     end

[Source]

    # File lib/coderay/encoders/xml.rb, line 62
62:     def end_group kind
63:       if @node == @root
64:         raise 'no token to close!'
65:       end
66:       @node = @node.parent
67:     end

[Source]

    # File lib/coderay/encoders/xml.rb, line 38
38:     def text_token text, kind
39:       if kind == :space
40:         token = @node
41:       else
42:         token = @node.add_element kind.to_s
43:       end
44:       text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl|
45:         case
46:         when space
47:           token << REXML::Text.new(space, true)
48:         when tab
49:           token << REXML::Text.new(tab, true)
50:         when nl
51:           token << REXML::Text.new(nl, true)
52:         else
53:           token << REXML::Text.new($&)
54:         end
55:       end
56:     end

Protected Instance methods

[Source]

    # File lib/coderay/encoders/xml.rb, line 31
31:     def finish options
32:       @doc.write @out, options[:pretty], options[:transitive], true
33:       
34:       super
35:     end

[Source]

    # File lib/coderay/encoders/xml.rb, line 22
22:     def setup options
23:       super
24:       
25:       @doc = REXML::Document.new
26:       @doc << REXML::XMLDecl.new
27:       @tab_width = options[:tab_width]
28:       @root = @node = @doc.add_element('coderay-tokens')
29:     end

[Validate]