Class HTML5::TreeBuilders::Base::TreeBuilder
In: lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb
Parent: Object
Phase XmlElementPhase InTablePhase RootElementPhase InHeadPhase AfterHeadPhase AfterFramesetPhase XmlRootPhase InitialPhase InTableBodyPhase InFramesetPhase InColumnGroupPhase InCaptionPhase TrailingEndPhase InSelectPhase BeforeHeadPhase InCellPhase InBodyPhase AfterBodyPhase InRowPhase Exception SerializeError EOF AssertionError ParseError HTMLSanitizer HTMLTokenizer XhmlRootPhase XMLParser XHTMLParser HTMLParser String EncodingBytes HTMLSerializer XHTMLSerializer TreeWalkers::Base NonRecursiveTreeWalker TreeWalker TreeWalker Base TreeWalker Element DocumentFragment Node CommentNode DocumentType TextNode Document Base::Node Node Node Base::TreeBuilder TreeBuilder TreeBuilder TreeBuilder Element DocumentFragment CommentNode DocumentType TextNode Document Element DocumentFragment CommentNode DocumentType TextNode Document Enumerable TestData Base OptionalTagFilter InjectMetaCharset WhitespaceFilter HTMLSanitizeFilter HTMLSanitizeModule SimpleDelegator HTMLInputStream EncodingParser ContentAttrParser Node TreeBuilder lib/feed_tools/vendor/html5/lib/html5/html5parser/trailing_end_phase.rb lib/feed_tools/vendor/html5/lib/html5/constants.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/after_frameset_phase.rb lib/feed_tools/vendor/html5/lib/html5/liberalxmlparser.rb lib/feed_tools/vendor/html5/lib/html5/serializer/xhtmlserializer.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_caption_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_frameset_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_table_body_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/initial_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/root_element_phase.rb lib/feed_tools/vendor/html5/lib/html5/serializer/htmlserializer.rb lib/feed_tools/vendor/html5/lib/html5/tokenizer.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/before_head_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_select_phase.rb lib/feed_tools/vendor/html5/lib/html5/inputstream.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_table_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_row_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_cell_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_body_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_head_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/after_body_phase.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/after_head_phase.rb lib/feed_tools/vendor/html5/lib/html5/sanitizer.rb lib/feed_tools/vendor/html5/lib/html5/html5parser/in_column_group_phase.rb lib/feed_tools/vendor/html5/lib/html5/treewalkers/base.rb lib/feed_tools/vendor/html5/lib/html5/treewalkers/hpricot.rb Hpricot TokenConstructor lib/feed_tools/vendor/html5/lib/html5/treewalkers/rexml.rb REXML lib/feed_tools/vendor/html5/lib/html5/treewalkers/simpletree.rb SimpleTree TreeWalkers HTMLSanitizeModule lib/feed_tools/vendor/html5/lib/html5/treebuilders/hpricot.rb Hpricot lib/feed_tools/vendor/html5/lib/html5/treebuilders/rexml.rb REXML lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb Base lib/feed_tools/vendor/html5/lib/html5/treebuilders/simpletree.rb SimpleTree TreeBuilders lib/feed_tools/vendor/html5/tests/preamble.rb TestSupport Sniffer lib/feed_tools/vendor/html5/lib/html5/filters/whitespace.rb lib/feed_tools/vendor/html5/lib/html5/filters/optionaltags.rb lib/feed_tools/vendor/html5/lib/html5/filters/base.rb lib/feed_tools/vendor/html5/lib/html5/filters/inject_meta_charset.rb lib/feed_tools/vendor/html5/lib/html5/filters/sanitizer.rb Filters HTML5 dot/m_66_0.png

Base treebuilder implementation

Methods

Attributes

activeFormattingElements  [RW] 
document  [RW] 
formPointer  [RW] 
head_pointer  [RW] 
open_elements  [RW] 

Public Class methods

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 104
104:         def initialize
105:           reset
106:         end

Public Instance methods

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 184
184:         def clearActiveFormattingElements
185:           {} until @activeFormattingElements.empty? || @activeFormattingElements.pop == Marker
186:         end

Create an element but don‘t insert it anywhere

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 214
214:         def createElement(name, attributes)
215:           element = @elementClass.new(name)
216:           element.attributes = attributes
217:           return element
218:         end

Check if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return false

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 191
191:         def elementInActiveFormattingElements(name)
192:           @activeFormattingElements.reverse.each do |element|
193:             # Check for Marker first because if it's a Marker it doesn't have a
194:             # name attribute.
195:             break if element == Marker
196:             return element if element.name == name
197:           end
198:           return false
199:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 121
121:         def elementInScope(target, tableVariant=false)
122:           # Exit early when possible.
123:           return true if @open_elements[-1].name == target
124: 
125:           # AT How about while true and simply set node to [-1] and set it to
126:           # [-2] at the end...
127:           @open_elements.reverse.each do |element|
128:             if element.name == target
129:               return true
130:             elsif element.name == 'table'
131:               return false
132:             elsif not tableVariant and SCOPING_ELEMENTS.include?(element.name)
133:               return false
134:             elsif element.name == 'html'
135:               return false
136:             end
137:           end
138:           assert false # We should never reach this point
139:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 302
302:         def generateImpliedEndTags(exclude=nil)
303:           name = @open_elements[-1].name
304: 
305:           # XXX td, th and tr are not actually needed
306:           if (%w[dd dt li p td th tr].include?(name) and name != exclude)
307:             @open_elements.pop
308:             # XXX This is not entirely what the specification says. We should
309:             # investigate it more closely.
310:             generateImpliedEndTags(exclude)
311:           end
312:         end

Get the foster parent element, and sibling to insert before (or nil) when inserting a misnested table node

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 274
274:         def getTableMisnestedNodePosition
275:           #The foster parent element is the one which comes before the most
276:           #recently opened table element
277:           #XXX - this is really inelegant
278:           lastTable = nil
279:           fosterParent = nil
280:           insertBefore = nil
281:           @open_elements.reverse.each do |element|
282:             if element.name == "table"
283:               lastTable = element
284:               break
285:             end
286:           end
287:           if lastTable
288:             #XXX - we should really check that this parent is actually a
289:             #node here
290:             if lastTable.parent
291:               fosterParent = lastTable.parent
292:               insertBefore = lastTable
293:             else
294:               fosterParent = @open_elements[@open_elements.index(lastTable) - 1]
295:             end
296:           else
297:             fosterParent = @open_elements[0]
298:           end
299:           return fosterParent, insertBefore
300:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 314
314:         def get_document
315:           @document
316:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 318
318:         def get_fragment
319:           #assert @inner_html
320:           fragment = @fragmentClass.new
321:           @open_elements[0].reparentChildren(fragment)
322:           return fragment
323:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 201
201:         def insertDoctype(name, public_id, system_id)
202:           doctype = @doctypeClass.new(name)
203:           doctype.public_id = public_id
204:           doctype.system_id = system_id
205:           @document.appendChild(doctype)
206:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 259
259:         def insertText(data, parent=nil)
260:           parent = @open_elements[-1] if parent.nil?
261: 
262:           if (not(@insert_from_table) or (@insert_from_table and not TABLE_INSERT_MODE_ELEMENTS.include?(@open_elements[-1].name)))
263:             parent.insertText(data)
264:           else
265:             #We should be in the InTable mode. This means we want to do
266:             #special magic element rearranging
267:             parent, insertBefore = getTableMisnestedNodePosition
268:             parent.insertText(data, insertBefore)
269:           end
270:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 208
208:         def insert_comment(data, parent=nil)
209:           parent = @open_elements[-1] if parent.nil?
210:           parent.appendChild(@commentClass.new(data))
211:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 227
227:         def insert_element(name, attributes)
228:           send(@insert_element, name, attributes)
229:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 231
231:         def insert_elementNormal(name, attributes)
232:           element = @elementClass.new(name)
233:           element.attributes = attributes
234:           @open_elements.last.appendChild(element)
235:           @open_elements.push(element)
236:           return element
237:         end

Create an element and insert it into the tree

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 240
240:         def insert_elementTable(name, attributes)
241:           element = @elementClass.new(name)
242:           element.attributes = attributes
243:           if TABLE_INSERT_MODE_ELEMENTS.include?(@open_elements.last.name)
244:             #We should be in the InTable mode. This means we want to do
245:             #special magic element rearranging
246:             parent, insertBefore = getTableMisnestedNodePosition
247:             if insertBefore.nil?
248:               parent.appendChild(element)
249:             else
250:               parent.insertBefore(element, insertBefore)
251:             end
252:             @open_elements.push(element)
253:           else
254:             return insert_elementNormal(name, attributes)
255:           end
256:           return element
257:         end

Switch the function used to insert an element from the normal one to the misnested table one and back again

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 222
222:         def insert_from_table=(value)
223:           @insert_from_table = value
224:           @insert_element = value ? :insert_elementTable : :insert_elementNormal
225:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 141
141:         def reconstructActiveFormattingElements
142:           # Within this algorithm the order of steps described in the
143:           # specification is not quite the same as the order of steps in the
144:           # code. It should still do the same though.
145: 
146:           # Step 1: stop the algorithm when there's nothing to do.
147:           return if @activeFormattingElements.empty?
148: 
149:           # Step 2 and step 3: we start with the last element. So i is -1.
150:           i = -1
151:           entry = @activeFormattingElements[i]
152:           return if entry == Marker or @open_elements.include?(entry)
153: 
154:           # Step 6
155:           until entry == Marker or @open_elements.include?(entry)
156:             # Step 5: let entry be one earlier in the list.
157:             i -= 1
158:             begin
159:               entry = @activeFormattingElements[i]
160:             rescue
161:               # Step 4: at this point we need to jump to step 8. By not doing
162:               # i += 1 which is also done in step 7 we achieve that.
163:               break
164:             end
165:           end
166:           while true
167:             # Step 7
168:             i += 1
169: 
170:             # Step 8
171:             clone = @activeFormattingElements[i].cloneNode
172: 
173:             # Step 9
174:             element = insert_element(clone.name, clone.attributes)
175: 
176:             # Step 10
177:             @activeFormattingElements[i] = element
178: 
179:             # Step 11
180:             break if element == @activeFormattingElements[-1]
181:           end
182:         end

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 108
108:         def reset
109:           @open_elements = []
110:           @activeFormattingElements = []
111: 
112:           #XXX - rename these to headElement, formElement
113:           @head_pointer = nil
114:           @formPointer = nil
115: 
116:           self.insert_from_table = false
117: 
118:           @document = @documentClass.new
119:         end

Serialize the subtree of node in the format required by unit tests node - the node from which to start serializing

[Source]

     # File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 327
327:         def testSerializer(node)
328:           raise NotImplementedError
329:         end

[Validate]