Class: HTML5::TreeBuilders::REXML::TextNode

Inherits:
Node show all
Defined in:
lib/html5/treebuilders/rexml.rb

Instance Attribute Summary

Attributes inherited from Node

#rxobj

Attributes inherited from Base::Node

#childNodes, #flags, #parent

Instance Method Summary collapse

Methods inherited from Node

#appendChild, #hasContent, #insertBefore, #insertText, #removeChild

Methods inherited from Base::Node

#appendChild, #cloneNode, #hasContent, #insertBefore, #insertText, #removeChild, #reparentChildren

Constructor Details

#initialize(data) ⇒ TextNode

Returns a new instance of TextNode.



161
162
163
164
165
166
167
168
# File 'lib/html5/treebuilders/rexml.rb', line 161

def initialize data
  raw = data.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;')
  if String.method_defined? :encode
    @rxobj = ::REXML::Text.new(raw.force_encoding('UTF-8'), true, nil, true)
  else
    @rxobj = ::REXML::Text.new(raw, true, nil, true)
  end
end

Instance Method Details

#printTree(indent = 0) ⇒ Object



170
171
172
# File 'lib/html5/treebuilders/rexml.rb', line 170

def printTree indent=0
  "\n|#{' ' * indent}\"#{rxobj.value}\""
end