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:source_maps/span.dart' show FileSpan; | 6 import 'package:source_maps/span.dart' show FileSpan; |
7 import 'constants.dart'; | 7 import 'constants.dart'; |
8 import 'list_proxy.dart'; | 8 import 'list_proxy.dart'; |
9 import 'token.dart'; | 9 import 'token.dart'; |
10 import 'utils.dart'; | 10 import 'utils.dart'; |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 /** | 317 /** |
318 * Insert [data] as text in the current node, positioned before the | 318 * Insert [data] as text in the current node, positioned before the |
319 * start of node [refNode] or to the end of the node's text. | 319 * start of node [refNode] or to the end of the node's text. |
320 */ | 320 */ |
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.value = '${last.value}$data'; | 327 last.data = '${last.data}$data'; |
328 | 328 |
329 if (span != null) { | 329 if (span != null) { |
330 last.sourceSpan = span.file.span(last.sourceSpan.start.offset, | 330 last.sourceSpan = span.file.span(last.sourceSpan.start.offset, |
331 span.end.offset); | 331 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.value = '${last.value}$data'; | 340 last.data = '${last.data}$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 /** | 347 /** |
348 * Get the foster parent element, and sibling to insert before | 348 * Get the foster parent element, and sibling to insert before |
349 * (or null) when inserting a misnested table node | 349 * (or null) when inserting a misnested table node |
350 */ | 350 */ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 Document getDocument() => document; | 392 Document getDocument() => document; |
393 | 393 |
394 /** Return the final fragment. */ | 394 /** Return the final fragment. */ |
395 DocumentFragment getFragment() { | 395 DocumentFragment getFragment() { |
396 //XXX assert innerHTML | 396 //XXX assert innerHTML |
397 var fragment = new DocumentFragment(); | 397 var fragment = new DocumentFragment(); |
398 openElements[0].reparentChildren(fragment); | 398 openElements[0].reparentChildren(fragment); |
399 return fragment; | 399 return fragment; |
400 } | 400 } |
401 } | 401 } |
OLD | NEW |