@@ -140,8 +140,10 @@ public function emitToken($token, $mode = null) {
140
140
if ($backtrace[1]['class'] !== 'HTML5_TreeConstructer') echo "--\n";
141
141
echo $this->strConst($mode) . "\n ";
142
142
token_dump($token);
143
+ $this->printStack();
144
+ $this->printActiveFormattingElements();
143
145
if ($this->foster_parent) echo " -> this is a foster parent mode\n";
144
- */
146
+ */
145
147
146
148
if ($ this ->ignore_lf_token )$ this ->ignore_lf_token --;
147
149
$ this ->ignored =false ;
@@ -1933,18 +1935,10 @@ public function emitToken($token, $mode = null) {
1933
1935
/* Parse error. Process the token as if the insertion mode was "in
1934
1936
body", with the following exception: */
1935
1937
1936
- /* If the current node is a table, tbody, tfoot, thead, or tr
1937
- element, then, whenever a node would be inserted into the current
1938
- node, it must instead be inserted into the foster parent element. */
1939
- if (in_array (end ($ this ->stack )->tagName ,
1940
- array ('table ' ,'tbody ' ,'tfoot ' ,'thead ' ,'tr ' ))) {
1941
- $ old =$ this ->foster_parent ;
1942
- $ this ->foster_parent =true ;
1943
- $ this ->processWithRulesFor ($ token ,self ::IN_BODY );
1944
- $ this ->foster_parent =$ old ;
1945
- }else {
1946
- $ this ->processWithRulesFor ($ token ,self ::IN_BODY );
1947
- }
1938
+ $ old =$ this ->foster_parent ;
1939
+ $ this ->foster_parent =true ;
1940
+ $ this ->processWithRulesFor ($ token ,self ::IN_BODY );
1941
+ $ this ->foster_parent =$ old ;
1948
1942
}
1949
1943
break ;
1950
1944
@@ -2788,7 +2782,12 @@ private function insertComment($data) {
2788
2782
}
2789
2783
2790
2784
private function appendToRealParent ($ node ) {
2791
- if (!$ this ->foster_parent ) {
2785
+ // this is only for the foster_parent case
2786
+ /* If the current node is a table, tbody, tfoot, thead, or tr
2787
+ element, then, whenever a node would be inserted into the current
2788
+ node, it must instead be inserted into the foster parent element. */
2789
+ if (!$ this ->foster_parent || !in_array (end ($ this ->stack )->tagName ,
2790
+ array ('table ' ,'tbody ' ,'tfoot ' ,'thead ' ,'tr ' ))) {
2792
2791
$ this ->appendChild (end ($ this ->stack ),$ node );
2793
2792
}else {
2794
2793
$ this ->fosterParent ($ node );
@@ -2910,7 +2909,7 @@ private function reconstructActiveFormattingElements() {
2910
2909
2911
2910
/* 9. Append clone to the current node and push it onto the stack
2912
2911
of open elements so that it is the new current node. */
2913
- end ( $ this ->stack )-> appendChild ($ clone );
2912
+ $ this ->appendToRealParent ($ clone );
2914
2913
$ this ->stack [] =$ clone ;
2915
2914
2916
2915
/* 10. Replace the entry for entry in the list with an entry for
@@ -3209,10 +3208,24 @@ public function fosterParent($node) {
3209
3208
* For debugging, prints the stack
3210
3209
*/
3211
3210
private function printStack () {
3212
- echo " Stack: \n" ;
3211
+ $ names = array () ;
3213
3212
foreach ($ this ->stack as $ i =>$ element ) {
3214
- echo " " . ($ i +1 ) .". " .$ element ->tagName ."\n" ;
3213
+ $ names [] =$ element ->tagName ;
3214
+ }
3215
+ echo " -> stack [ " .implode (', ' ,$ names ) ."] \n" ;
3216
+ }
3217
+
3218
+ /**
3219
+ * For debugging, prints active formatting elements
3220
+ */
3221
+ private function printActiveFormattingElements () {
3222
+ if (!$ this ->a_formatting )return ;
3223
+ $ names =array ();
3224
+ foreach ($ this ->a_formatting as $ node ) {
3225
+ if ($ node ===self ::MARKER )$ names [] ='MARKER ' ;
3226
+ else $ names [] =$ node ->tagName ;
3215
3227
}
3228
+ echo " -> active formatting [ " .implode (', ' ,$ names ) ."] \n" ;
3216
3229
}
3217
3230
3218
3231
public function currentTableIsTainted () {