| Class | CodeRay::Encoders::XML |
| In: |
lib/coderay/encoders/xml.rb
|
| Parent: | Encoder |
| FILE_EXTENSION | = | 'xml' |
| DEFAULT_OPTIONS | = | { :tab_width => 8, :pretty => -1, :transitive => false, } |
# File lib/coderay/encoders/xml.rb, line 58
58: def begin_group kind
59: @node = @node.add_element kind.to_s
60: end
# 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
# 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
# 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