REXML Trees

Synced with latest HTML5lib.
Added preliminary support (currently disabled) for sanitizing REXML trees.
This commit is contained in:
Jacques Distler 2007-06-05 16:34:49 -05:00
parent 4dd70af5ae
commit bd8ba1f4b1
28 changed files with 1317 additions and 112 deletions

View file

@ -144,7 +144,7 @@ module HTML5lib
# code. It should still do the same though.
# Step 1: stop the algorithm when there's nothing to do.
return unless @activeFormattingElements
return if @activeFormattingElements.empty?
# Step 2 and step 3: we start with the last element. So i is -1.
i = -1

View file

@ -1,4 +1,5 @@
require 'html5lib/treebuilders/base'
require 'rubygems'
require 'hpricot'
require 'forwardable'
@ -26,12 +27,14 @@ module HTML5lib
childNodes << node
hpricot.children << node.hpricot
end
node.hpricot.parent = hpricot
node.parent = self
end
def removeChild(node)
childNodes.delete(node)
hpricot.children.delete_at(hpricot.children.index(node.hpricot))
node.hpricot.parent = nil
node.parent = nil
end
@ -48,6 +51,7 @@ module HTML5lib
if node.kind_of?(TextNode) and index > 0 and childNodes[index-1].kind_of?(TextNode)
childNodes[index-1].hpricot.content = childNodes[index-1].hpricot.to_s + node.hpricot.to_s
else
refNode.hpricot.parent.insert_before(node.hpricot,refNode.hpricot)
childNodes.insert(index, node)
end
end

View file

@ -4,7 +4,7 @@ require 'forwardable'
module HTML5lib
module TreeBuilders
module REXMLTree
module REXML
class Node < Base::Node
extend Forwardable
@ -52,6 +52,7 @@ module HTML5lib
childNodes[index-1].rxobj.raw = true
else
childNodes.insert index, node
refNode.rxobj.parent.insert_before(refNode.rxobj,node.rxobj)
end
end
@ -62,7 +63,7 @@ module HTML5lib
class Element < Node
def self.rxclass
REXML::Element
::REXML::Element
end
def initialize name
@ -95,7 +96,7 @@ module HTML5lib
class Document < Node
def self.rxclass
REXML::Document
::REXML::Document
end
def initialize
@ -120,7 +121,7 @@ module HTML5lib
class DocumentType < Node
def self.rxclass
REXML::DocType
::REXML::DocType
end
def printTree indent=0
@ -145,7 +146,7 @@ module HTML5lib
class TextNode < Node
def initialize data
raw=data.gsub('&','&amp;').gsub('<','&lt;').gsub('>','&gt;')
@rxobj = REXML::Text.new(raw, true, nil, true)
@rxobj = ::REXML::Text.new(raw, true, nil, true)
end
def printTree indent=0
@ -155,7 +156,7 @@ module HTML5lib
class CommentNode < Node
def self.rxclass
REXML::Comment
::REXML::Comment
end
def printTree indent=0