| OLD | NEW |
| 1 /// Internals to the tree builders. | 1 /// Internals to the tree builders. |
| 2 library treebuilder; | 2 library treebuilder; |
| 3 | 3 |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'package:html5lib/dom.dart'; | 5 import 'package:html5lib/dom.dart'; |
| 6 import 'package:html5lib/parser.dart' show getElementNameTuple; | 6 import 'package:html5lib/parser.dart' show getElementNameTuple; |
| 7 import 'package:source_maps/span.dart' show FileSpan; | 7 import 'package:source_maps/span.dart' show FileSpan; |
| 8 import 'constants.dart'; | 8 import 'constants.dart'; |
| 9 import 'list_proxy.dart'; | 9 import 'list_proxy.dart'; |
| 10 import 'token.dart'; | 10 import 'token.dart'; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 parent = openElements.last; | 244 parent = openElements.last; |
| 245 } | 245 } |
| 246 parent.nodes.add(new Comment(token.data)..sourceSpan = token.span); | 246 parent.nodes.add(new Comment(token.data)..sourceSpan = token.span); |
| 247 } | 247 } |
| 248 | 248 |
| 249 /// Create an element but don't insert it anywhere | 249 /// Create an element but don't insert it anywhere |
| 250 Element createElement(StartTagToken token) { | 250 Element createElement(StartTagToken token) { |
| 251 var name = token.name; | 251 var name = token.name; |
| 252 var namespace = token.namespace; | 252 var namespace = token.namespace; |
| 253 if (namespace == null) namespace = defaultNamespace; | 253 if (namespace == null) namespace = defaultNamespace; |
| 254 var element = new Element(name, namespace) | 254 var element = document.createElementNS(namespace, name) |
| 255 ..attributes = token.data | 255 ..attributes = token.data |
| 256 ..sourceSpan = token.span; | 256 ..sourceSpan = token.span; |
| 257 return element; | 257 return element; |
| 258 } | 258 } |
| 259 | 259 |
| 260 Element insertElement(StartTagToken token) { | 260 Element insertElement(StartTagToken token) { |
| 261 if (insertFromTable) return insertElementTable(token); | 261 if (insertFromTable) return insertElementTable(token); |
| 262 return insertElementNormal(token); | 262 return insertElementNormal(token); |
| 263 } | 263 } |
| 264 | 264 |
| 265 Element insertElementNormal(StartTagToken token) { | 265 Element insertElementNormal(StartTagToken token) { |
| 266 var name = token.name; | 266 var name = token.name; |
| 267 var namespace = token.namespace; | 267 var namespace = token.namespace; |
| 268 if (namespace == null) namespace = defaultNamespace; | 268 if (namespace == null) namespace = defaultNamespace; |
| 269 var element = new Element(name, namespace) | 269 var element = document.createElementNS(namespace, name) |
| 270 ..attributes = token.data | 270 ..attributes = token.data |
| 271 ..sourceSpan = token.span; | 271 ..sourceSpan = token.span; |
| 272 openElements.last.nodes.add(element); | 272 openElements.last.nodes.add(element); |
| 273 openElements.add(element); | 273 openElements.add(element); |
| 274 return element; | 274 return element; |
| 275 } | 275 } |
| 276 | 276 |
| 277 Element insertElementTable(token) { | 277 Element insertElementTable(token) { |
| 278 /// Create an element and insert it into the tree | 278 /// Create an element and insert it into the tree |
| 279 var element = createElement(token); | 279 var element = createElement(token); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 var insertBefore = null; | 350 var insertBefore = null; |
| 351 for (var elm in openElements.reversed) { | 351 for (var elm in openElements.reversed) { |
| 352 if (elm.localName == "table") { | 352 if (elm.localName == "table") { |
| 353 lastTable = elm; | 353 lastTable = elm; |
| 354 break; | 354 break; |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 if (lastTable != null) { | 357 if (lastTable != null) { |
| 358 // XXX - we should really check that this parent is actually a | 358 // XXX - we should really check that this parent is actually a |
| 359 // node here | 359 // node here |
| 360 if (lastTable.parent != null) { | 360 if (lastTable.parentNode != null) { |
| 361 fosterParent = lastTable.parent; | 361 fosterParent = lastTable.parentNode; |
| 362 insertBefore = lastTable; | 362 insertBefore = lastTable; |
| 363 } else { | 363 } else { |
| 364 fosterParent = openElements[openElements.indexOf(lastTable) - 1]; | 364 fosterParent = openElements[openElements.indexOf(lastTable) - 1]; |
| 365 } | 365 } |
| 366 } else { | 366 } else { |
| 367 fosterParent = openElements[0]; | 367 fosterParent = openElements[0]; |
| 368 } | 368 } |
| 369 return [fosterParent, insertBefore]; | 369 return [fosterParent, insertBefore]; |
| 370 } | 370 } |
| 371 | 371 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 385 Document getDocument() => document; | 385 Document getDocument() => document; |
| 386 | 386 |
| 387 /// Return the final fragment. | 387 /// Return the final fragment. |
| 388 DocumentFragment getFragment() { | 388 DocumentFragment getFragment() { |
| 389 //XXX assert innerHTML | 389 //XXX assert innerHTML |
| 390 var fragment = new DocumentFragment(); | 390 var fragment = new DocumentFragment(); |
| 391 openElements[0].reparentChildren(fragment); | 391 openElements[0].reparentChildren(fragment); |
| 392 return fragment; | 392 return fragment; |
| 393 } | 393 } |
| 394 } | 394 } |
| OLD | NEW |