8000 Start adding XDOM markers for transition away from DOM. · html5lib/html5lib-php@901876f · GitHub
[go: up one dir, main page]

Skip to content

Commit 901876f

Browse files
author
Edward Z. Yang ext:(%22)
committed
Start adding XDOM markers for transition away from DOM.
1 parent 8e12e67 commit 901876f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

library/HTML5/TreeBuilder.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
// XERROR - with regards to parse errors
3232
// XSCRIPT - with regards to scripting mode
3333
// XENCODING - with regards to encoding (for reparsing tests)
34+
// XDOM - DOM specific code (tagName is explicitly not marked).
35+
// this is not (yet) in helper functions.
3436

3537
class HTML5_TreeBuilder {
3638
public $stack = array();
@@ -205,6 +207,7 @@ public function emitToken($token, $mode = null) {
205207
* doctype attribute of the Document object. */
206208
if (!isset($token['public'])) $token['public'] = null;
207209
if (!isset($token['system'])) $token['system'] = null;
210+
// XDOM
208211
// Yes this is hacky. I'm kind of annoyed that I can't appendChild
209212
// a doctype to DOMDocument. Maybe I haven't chanted the right
210213
// syllables.
@@ -367,6 +370,7 @@ public function emitToken($token, $mode = null) {
367370
} elseif($token['type'] === HTML5_Tokenizer::COMMENT) {
368371
/* Append a Comment node to the Document object with the data
369372
attribute set to the data given in the comment token. */
373+
// XDOM
370374
$comment = $this->dom->createComment($token['data']);
371375
$this->dom->appendChild($comment);
372376

@@ -382,6 +386,7 @@ public function emitToken($token, $mode = null) {
382386
/* Create an element for the token in the HTML namespace. Append it
383387
* to the Document object. Put this element in the stack of open
384388
* elements. */
389+
// XDOM
385390
$html = $this->insertElement($token, false);
386391
$this->dom->appendChild($html);
387392
$this->stack[] = $html;
@@ -391,6 +396,7 @@ public function emitToken($token, $mode = null) {
391396
} else {
392397
/* Create an html element. Append it to the Document object. Put
393398
* this element in the stack of open elements. */
399+
// XDOM
394400
$html = $this->dom->createElementNS(self::NS_HTML, 'html');
395401
$this->dom->appendChild($html);
396402
$this->stack[] = $html;
@@ -1748,6 +1754,7 @@ public function emitToken($token, $mode = null) {
17481754
* elements with an entry for the new element, and
17491755
* let node be the new element. */
17501756
// we don't know what the token is anymore
1757+
// XDOM
17511758
$clone = $node->cloneNode();
17521759
$a_pos = array_search($node, $this->a_formatting, true);
17531760
$s_pos = array_search($node, $this->stack, true);
@@ -1757,10 +1764,12 @@ public function emitToken($token, $mode = null) {
17571764

17581765
/* 6.6 Insert last node into node, first removing
17591766
it from its previous parent node if any. */
1767+
// XDOM
17601768
if($last_node->parentNode !== null) {
17611769
$last_node->parentNode->removeChild($last_node);
17621770
}
17631771

1772+
// XDOM
17641773
$node->appendChild($last_node);
17651774

17661775
/* 6.7 Let last node be node. */
@@ -1774,6 +1783,7 @@ public function emitToken($token, $mode = null) {
17741783
* whatever last node ended up being in the previous
17751784
* step, first removing it from its previous parent
17761785
* node if any. */
1786+
// XDOM
17771787
if ($last_node->parentNode) { // common step
17781788
$last_node->parentNode->removeChild($last_node);
17791789
}
@@ -1784,23 +1794,27 @@ public function emitToken($token, $mode = null) {
17841794
* first removing it from its previous parent node if
17851795
* any. */
17861796
} else {
1797+
// XDOM
17871798
$common_ancestor->appendChild($last_node);
17881799
}
17891800

17901801
/* 8. Create an element for the token for which the
17911802
* formatting element was created. */
1803+
// XDOM
17921804
$clone = $formatting_element->cloneNode();
17931805

17941806
/* 9. Take all of the child nodes of the furthest
17951807
block and append them to the element created in the
17961808
last step. */
1809+
// XDOM
17971810
while($furthest_block->hasChildNodes()) {
17981811
$child = $furthest_block->firstChild;
17991812
$furthest_block->removeChild($child);
18001813
$clone->appendChild($child);
18011814
}
18021815

18031816
/* 10. Append that clone to the furthest block. */
1817+
// XDOM
18041818
$furthest_block->appendChild($clone);
18051819

18061820
/* 11. Remove the formatting element from the list
@@ -2753,6 +2767,7 @@ public function emitToken($token, $mode = null) {
27532767
// XERROR: parse error
27542768
} elseif ($token['type'] === HTML5_Tokenizer::ENDTAG &&
27552769
$token['name'] === 'script' && end($this->stack)->tagName === 'script' &&
2770+
// XDOM
27562771
end($this->stack)->namespaceURI === self::NS_SVG) {
27572772
array_pop($this->stack);
27582773
// a bunch of script running mumbo jumbo
@@ -2761,20 +2776,23 @@ public function emitToken($token, $mode = null) {
27612776
((
27622777
$token['name'] !== 'mglyph' &&
27632778
$token['name'] !== 'malignmark' &&
2779+
// XDOM
27642780
end($this->stack)->namespaceURI === self::NS_MATHML &&
27652781
in_array(end($this->stack)->tagName, array('mi', 'mo', 'mn', 'ms', 'mtext'))
27662782
) ||
27672783
(
27682784
$token['name'] === 'svg' &&
2785+
// XDOM
27692786
end($this->stack)->namespaceURI === self::NS_MATHML &&
27702787
end($this->stack)->tagName === 'annotation-xml'
27712788
) ||
27722789
(
2790+
// XDOM
27732791
end($this->stack)->namespaceURI === self::NS_SVG &&
27742792
in_array(end($this->stack)->tagName, array('foreignObject', 'desc', 'title'))
27752793
) ||
27762794
(
2777-
// XSKETCHY
2795+
// XSKETCHY && XDOM
27782796
end($this->stack)->namespaceURI === self::NS_HTML
27792797
))
27802798
) || $token['type'] === HTML5_Tokenizer::ENDTAG
@@ -2788,6 +2806,7 @@ public function emitToken($token, $mode = null) {
27882806
$found = false;
27892807
// this basically duplicates elementInScope()
27902808
for ($i = count($this->stack) - 1; $i >= 0; $i--) {
2809+
// XDOM
27912810
$node = $this->stack[$i];
27922811
if ($node->namespaceURI !== self::NS_HTML) {
27932812
$found = true;
@@ -2815,6 +2834,7 @@ public function emitToken($token, $mode = null) {
28152834
// XERROR: parse error
28162835
do {
28172836
$node = array_pop($this->stack);
2837+
// XDOM
28182838
} while ($node->namespaceURI !== self::NS_HTML);
28192839
$this->stack[] = $node;
28202840
$this->mode = $this->secondary_mode;
@@ -2858,6 +2878,7 @@ public function emitToken($token, $mode = null) {
28582878
'radialgradient' => 'radialGradient',
28592879
'textpath' => 'textPath',
28602880
);
2881+
// XDOM
28612882
$current = end($this->stack);
28622883
if ($current->namespaceURI === self::NS_MATHML) {
28632884
$token = $this->adjustMathMLAttributes($token);
@@ -2894,6 +2915,7 @@ public function emitToken($token, $mode = null) {
28942915
/* Append a Comment node to the first element in the stack of open
28952916
elements (the html element), with the data attribute set to the
28962917
data given in the comment token. */
2918+
// XDOM
28972919
$comment = $this->dom->createComment($token['data']);
28982920
$this->stack[0]->appendChild($comment);
28992921

@@ -3044,6 +3066,7 @@ public function emitToken($token, $mode = null) {
30443066
if($token['type'] === HTML5_Tokenizer::COMMENT) {
30453067
/* Append a Comment node to the Document object with the data
30463068
attribute set to the data given in the comment token. */
3069+
// XDOM
30473070
$comment = $this->dom->createComment($token['data']);
30483071
$this->dom->appendChild($comment);
30493072

@@ -3067,6 +3090,7 @@ public function emitToken($token, $mode = null) {
30673090
if($token['type'] === HTML5_Tokenizer::COMMENT) {
30683091
/* Append a Comment node to the Document object with the data
30693092
attribute set to the data given in the comment token. */
3093+
// XDOM
30703094
$comment = $this->dom->createComment($token['data']);
30713095
$this->dom->appendChild($comment);
30723096

0 commit comments

Comments
 (0)
0