| 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:html/dom.dart'; | 5 import 'package:html/dom.dart'; |
| 6 import 'package:html/parser.dart' show getElementNameTuple; | 6 import 'package:html/parser.dart' show getElementNameTuple; |
| 7 import 'package:source_span/source_span.dart'; | 7 import 'package:source_span/source_span.dart'; |
| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 } | 317 } |
| 318 | 318 |
| 319 /// Insert [data] as text in the current node, positioned before the | 319 /// Insert [data] as text in the current node, positioned before the |
| 320 /// start of node [refNode] or to the end of the node's text. | 320 /// start of node [refNode] or to the end of the node's text. |
| 321 static void _insertText(Node parent, String data, FileSpan span, | 321 static void _insertText(Node parent, String data, FileSpan span, |
| 322 [Element refNode]) { | 322 [Element refNode]) { |
| 323 var nodes = parent.nodes; | 323 var nodes = parent.nodes; |
| 324 if (refNode == null) { | 324 if (refNode == null) { |
| 325 if (nodes.length > 0 && nodes.last is Text) { | 325 if (nodes.length > 0 && nodes.last is Text) { |
| 326 Text last = nodes.last; | 326 Text last = nodes.last; |
| 327 last.data = '${last.data}$data'; | 327 last.appendData(data); |
| 328 | 328 |
| 329 if (span != null) { | 329 if (span != null) { |
| 330 last.sourceSpan = | 330 last.sourceSpan = |
| 331 span.file.span(last.sourceSpan.start.offset, span.end.offset); | 331 span.file.span(last.sourceSpan.start.offset, span.end.offset); |
| 332 } | 332 } |
| 333 } else { | 333 } else { |
| 334 nodes.add(new Text(data)..sourceSpan = span); | 334 nodes.add(new Text(data)..sourceSpan = span); |
| 335 } | 335 } |
| 336 } else { | 336 } else { |
| 337 int index = nodes.indexOf(refNode); | 337 int index = nodes.indexOf(refNode); |
| 338 if (index > 0 && nodes[index - 1] is Text) { | 338 if (index > 0 && nodes[index - 1] is Text) { |
| 339 Text last = nodes[index - 1]; | 339 Text last = nodes[index - 1]; |
| 340 last.data = '${last.data}$data'; | 340 last.appendData(data); |
| 341 } else { | 341 } else { |
| 342 nodes.insert(index, new Text(data)..sourceSpan = span); | 342 nodes.insert(index, new Text(data)..sourceSpan = span); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 | 346 |
| 347 /// Get the foster parent element, and sibling to insert before | 347 /// Get the foster parent element, and sibling to insert before |
| 348 /// (or null) when inserting a misnested table node | 348 /// (or null) when inserting a misnested table node |
| 349 List<Node> getTableMisnestedNodePosition() { | 349 List<Node> getTableMisnestedNodePosition() { |
| 350 // The foster parent element is the one which comes before the most | 350 // The foster parent element is the one which comes before the most |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 Document getDocument() => document; | 399 Document getDocument() => document; |
| 400 | 400 |
| 401 /// Return the final fragment. | 401 /// Return the final fragment. |
| 402 DocumentFragment getFragment() { | 402 DocumentFragment getFragment() { |
| 403 //XXX assert innerHTML | 403 //XXX assert innerHTML |
| 404 var fragment = new DocumentFragment(); | 404 var fragment = new DocumentFragment(); |
| 405 openElements[0].reparentChildren(fragment); | 405 openElements[0].reparentChildren(fragment); |
| 406 return fragment; | 406 return fragment; |
| 407 } | 407 } |
| 408 } | 408 } |
| OLD | NEW |