| OLD | NEW |
| 1 /// This library has a parser for HTML5 documents, that lets you parse HTML | 1 /// This library has a parser for HTML5 documents, that lets you parse HTML |
| 2 /// easily from a script or server side application: | 2 /// easily from a script or server side application: |
| 3 /// | 3 /// |
| 4 /// import 'package:html5lib/parser.dart' show parse; | 4 /// import 'package:html5lib/parser.dart' show parse; |
| 5 /// import 'package:html5lib/dom.dart'; | 5 /// import 'package:html5lib/dom.dart'; |
| 6 /// main() { | 6 /// main() { |
| 7 /// var document = parse( | 7 /// var document = parse( |
| 8 /// '<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!'); | 8 /// '<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!'); |
| 9 /// print(document.outerHtml); | 9 /// print(document.outerHtml); |
| 10 /// } | 10 /// } |
| (...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 }); | 1306 }); |
| 1307 } | 1307 } |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 void startTagFrameset(StartTagToken token) { | 1310 void startTagFrameset(StartTagToken token) { |
| 1311 parser.parseError(token.span, "unexpected-start-tag", {"name": "frameset"}); | 1311 parser.parseError(token.span, "unexpected-start-tag", {"name": "frameset"}); |
| 1312 if ((tree.openElements.length == 1 || | 1312 if ((tree.openElements.length == 1 || |
| 1313 tree.openElements[1].localName != "body")) { | 1313 tree.openElements[1].localName != "body")) { |
| 1314 assert(parser.innerHTMLMode); | 1314 assert(parser.innerHTMLMode); |
| 1315 } else if (parser.framesetOK) { | 1315 } else if (parser.framesetOK) { |
| 1316 if (tree.openElements[1].parent != null) { | 1316 if (tree.openElements[1].parentNode != null) { |
| 1317 tree.openElements[1].parent.nodes.remove(tree.openElements[1]); | 1317 tree.openElements[1].parentNode.nodes.remove(tree.openElements[1]); |
| 1318 } | 1318 } |
| 1319 while (tree.openElements.last.localName != "html") { | 1319 while (tree.openElements.last.localName != "html") { |
| 1320 tree.openElements.removeLast(); | 1320 tree.openElements.removeLast(); |
| 1321 } | 1321 } |
| 1322 tree.insertElement(token); | 1322 tree.insertElement(token); |
| 1323 parser.phase = parser._inFramesetPhase; | 1323 parser.phase = parser._inFramesetPhase; |
| 1324 } | 1324 } |
| 1325 } | 1325 } |
| 1326 | 1326 |
| 1327 void startTagCloseP(StartTagToken token) { | 1327 void startTagCloseP(StartTagToken token) { |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1833 // Step 6.3 | 1833 // Step 6.3 |
| 1834 if (node == formattingElement) { | 1834 if (node == formattingElement) { |
| 1835 break; | 1835 break; |
| 1836 } | 1836 } |
| 1837 // Step 6.4 | 1837 // Step 6.4 |
| 1838 if (lastNode == furthestBlock) { | 1838 if (lastNode == furthestBlock) { |
| 1839 bookmark = (tree.activeFormattingElements.indexOf(node) + 1); | 1839 bookmark = (tree.activeFormattingElements.indexOf(node) + 1); |
| 1840 } | 1840 } |
| 1841 // Step 6.5 | 1841 // Step 6.5 |
| 1842 //cite = node.parent | 1842 //cite = node.parent |
| 1843 var clone = node.clone(); | 1843 var clone = node.clone(false); |
| 1844 // Replace node with clone | 1844 // Replace node with clone |
| 1845 tree.activeFormattingElements[ | 1845 tree.activeFormattingElements[ |
| 1846 tree.activeFormattingElements.indexOf(node)] = clone; | 1846 tree.activeFormattingElements.indexOf(node)] = clone; |
| 1847 tree.openElements[tree.openElements.indexOf(node)] = clone; | 1847 tree.openElements[tree.openElements.indexOf(node)] = clone; |
| 1848 node = clone; | 1848 node = clone; |
| 1849 | 1849 |
| 1850 // Step 6.6 | 1850 // Step 6.6 |
| 1851 // Remove lastNode from its parents, if any | 1851 // Remove lastNode from its parents, if any |
| 1852 if (lastNode.parent != null) { | 1852 if (lastNode.parentNode != null) { |
| 1853 lastNode.parent.nodes.remove(lastNode); | 1853 lastNode.parentNode.nodes.remove(lastNode); |
| 1854 } | 1854 } |
| 1855 node.nodes.add(lastNode); | 1855 node.nodes.add(lastNode); |
| 1856 // Step 7.7 | 1856 // Step 7.7 |
| 1857 lastNode = node; | 1857 lastNode = node; |
| 1858 // End of inner loop | 1858 // End of inner loop |
| 1859 } | 1859 } |
| 1860 | 1860 |
| 1861 // Step 7 | 1861 // Step 7 |
| 1862 // Foster parent lastNode if commonAncestor is a | 1862 // Foster parent lastNode if commonAncestor is a |
| 1863 // table, tbody, tfoot, thead, or tr we need to foster parent the | 1863 // table, tbody, tfoot, thead, or tr we need to foster parent the |
| 1864 // lastNode | 1864 // lastNode |
| 1865 if (lastNode.parent != null) { | 1865 if (lastNode.parentNode != null) { |
| 1866 lastNode.parent.nodes.remove(lastNode); | 1866 lastNode.parentNode.nodes.remove(lastNode); |
| 1867 } | 1867 } |
| 1868 | 1868 |
| 1869 if (const ["table", "tbody", "tfoot", "thead", "tr"].contains( | 1869 if (const ["table", "tbody", "tfoot", "thead", "tr"].contains( |
| 1870 commonAncestor.localName)) { | 1870 commonAncestor.localName)) { |
| 1871 var nodePos = tree.getTableMisnestedNodePosition(); | 1871 var nodePos = tree.getTableMisnestedNodePosition(); |
| 1872 nodePos[0].insertBefore(lastNode, nodePos[1]); | 1872 nodePos[0].insertBefore(lastNode, nodePos[1]); |
| 1873 } else { | 1873 } else { |
| 1874 commonAncestor.nodes.add(lastNode); | 1874 commonAncestor.nodes.add(lastNode); |
| 1875 } | 1875 } |
| 1876 | 1876 |
| 1877 // Step 8 | 1877 // Step 8 |
| 1878 var clone = formattingElement.clone(); | 1878 var clone = formattingElement.clone(false); |
| 1879 | 1879 |
| 1880 // Step 9 | 1880 // Step 9 |
| 1881 furthestBlock.reparentChildren(clone); | 1881 furthestBlock.reparentChildren(clone); |
| 1882 | 1882 |
| 1883 // Step 10 | 1883 // Step 10 |
| 1884 furthestBlock.nodes.add(clone); | 1884 furthestBlock.nodes.add(clone); |
| 1885 | 1885 |
| 1886 // Step 11 | 1886 // Step 11 |
| 1887 tree.activeFormattingElements.remove(formattingElement); | 1887 tree.activeFormattingElements.remove(formattingElement); |
| 1888 tree.activeFormattingElements.insert( | 1888 tree.activeFormattingElements.insert( |
| (...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3358 } | 3358 } |
| 3359 } | 3359 } |
| 3360 | 3360 |
| 3361 | 3361 |
| 3362 /// Convenience function to get the pair of namespace and localName. | 3362 /// Convenience function to get the pair of namespace and localName. |
| 3363 Pair<String, String> getElementNameTuple(Element e) { | 3363 Pair<String, String> getElementNameTuple(Element e) { |
| 3364 var ns = e.namespaceUri; | 3364 var ns = e.namespaceUri; |
| 3365 if (ns == null) ns = Namespaces.html; | 3365 if (ns == null) ns = Namespaces.html; |
| 3366 return new Pair(ns, e.localName); | 3366 return new Pair(ns, e.localName); |
| 3367 } | 3367 } |
| OLD | NEW |