@@ -21,18 +21,18 @@ class Tests_HtmlApi_WpHtmlProcessorHtml5lib extends WP_UnitTestCase {
2121 const SKIP_HEAD_TESTS = true ;
2222
2323 const SKIP_TESTS = array (
24- 'adoption01/case10 - line 159 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
25- 'adoption01/case17 - line 318 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
26- 'adoption01/case4 - line 46 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
27- 'tests15/case1 - line 1 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
28- 'tests15/case2 - line 22 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
29- 'tests20/case38 - line 483 ' => 'XMP is a special token an needs a closer. ' ,
30- 'tests20/case39 - line 497 ' => "Closing P tag implicitly creates opener, which we don't visit. " ,
31- 'tests23/case1 - line 1 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
32- 'tests23/case2 - line 41 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
33- 'tests23/case3 - line 69 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
34- 'tests23/case4 - line 101 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
35- 'tests26/case10 - line 263 ' => 'Newline at end of tag triggers reconstruction of active formatting elements. ' ,
24+ // 'adoption01/line0159 ' => 'Unimplemented: Reconstruction of active formatting elements.',
25+ // 'adoption01/line0318 ' => 'Unimplemented: Reconstruction of active formatting elements.',
26+ // 'adoption01/line0046' => 'Unimplemented: Reconstruction of active formatting elements.',
27+ // 'tests15/line0001' => 'Unimplemented: Reconstruction of active formatting elements.',
28+ // 'tests15/line0022' => 'Unimplemented: Reconstruction of active formatting elements.',
29+ // 'tests20/line0483 ' => 'XMP is a special token an needs a closer.',
30+ // 'tests20/line0497 ' => "Closing P tag implicitly creates opener, which we don't visit.",
31+ // 'tests23/line0001' => 'Unimplemented: Reconstruction of active formatting elements.',
32+ // 'tests23/line0041' => 'Unimplemented: Reconstruction of active formatting elements.',
33+ // 'tests23/line0069' => 'Unimplemented: Reconstruction of active formatting elements.',
34+ // 'tests23/line0101' => 'Unimplemented: Reconstruction of active formatting elements.',
35+ // 'tests26/line0263 ' => 'Newline at end of tag triggers reconstruction of active formatting elements.',
3636 );
3737
3838 /**
@@ -77,9 +77,9 @@ public function data_external_html5lib_tests() {
7777
7878 // These tests contain no tags, which isn't yet
7979 // supported by the HTML API.
80- if ( 'comments01.dat ' === $ entry ) {
81- continue ;
82- }
80+ // if ( 'comments01.dat' === $entry ) {
81+ // continue;
82+ // }
8383
8484 foreach ( self ::parse_html5_dat_testfile ( $ test_dir . $ entry ) as $ k => $ test ) {
8585 // strip .dat extension from filename
@@ -106,21 +106,77 @@ public static function build_html5_treelike_string( $fragment_context, $html ) {
106106 }
107107
108108 $ output = "<html> \n <head> \n <body> \n" ;
109- while ( $ p ->next_tag () ) {
110- // Breadcrumbs include this tag, so skip 1 nesting level.
111- foreach ( $ p ->get_breadcrumbs () as $ index => $ _ ) {
112- if ( $ index ) {
113- $ output .= ' ' ;
109+
110+ $ has_set_current_tag = false ;
111+ while ( $ p ->next_token () ) {
112+ $ token_type = $ p ->get_token_type ();
113+
114+ $ p ->set_bookmark ('resume ' );
115+ if ( $ token_type === '#tag ' ) {
116+ $ p ->set_bookmark ('current_tag ' );
117+ $ has_set_current_tag = true ;
118+ }
119+
120+ if ( $ has_set_current_tag ) {
121+ $ p ->seek ('current_tag ' );
122+ foreach ( $ p ->get_breadcrumbs () as $ index => $ _ ) {
123+ if ( $ index ) {
124+ $ output .= ' ' ;
125+ }
114126 }
127+ $ p ->seek ('resume ' );
128+ } else {
129+ // If we haven't found a tag, we're text under
130+ $ output .= ' ' ;
131+ }
132+
133+ switch ( $ token_type ) {
134+ case '#tag ' :
135+ $ t = strtolower ( $ p ->get_tag () );
136+ $ output .= "< {$ t }> \n" ;
137+ break ;
138+
139+ case '#text ' :
140+ $ output .= '" ' . $ p ->get_modifiable_text () . "\"\n" ;
141+ break ;
142+
143+ case '#cdata-section ' :
144+ break ;
145+ case '#processing-instruction ' :
146+ break ;
147+ case '#comment ' :
148+ // Comments must be "<" then "!-- " then the data then " -->".
149+ $ output .= "<!-- " . $ p ->get_modifiable_text () . " --> \n" ;
150+ break ;
151+
152+ case '#doctype ' :
153+ break ;
154+ case '#presumptuous-tag ' :
155+ break ;
156+ case '#funky-comment ' :
157+ break ;
115158 }
116- $ t = strtolower ( $ p ->get_tag () );
117- $ output .= "< {$ t }> \n" ;
118159 }
119160
161+ // while ( $p->next_tag() ) {
162+ // // Breadcrumbs include this tag, so skip 1 nesting level.
163+ // foreach ( $p->get_breadcrumbs() as $index => $_ ) {
164+ // if ( $index ) {
165+ // $output .= ' ';
166+ // }
167+ // }
168+ // $t = strtolower( $p->get_tag() );
169+ // $output .= "<{$t}>\n";
170+ // }
171+
120172 if ( WP_HTML_Processor::ERROR_UNSUPPORTED === $ p ->get_last_error () ) {
121173 return null ;
122174 }
123175
176+ if ( $ p ->paused_at_incomplete_token () ) {
177+ return null ;
178+ }
179+
124180 return $ output ;
125181 }
126182
@@ -229,13 +285,13 @@ public static function parse_html5_dat_testfile( $filename ) {
229285 // Ignore everything that doesn't look like an element.
230286 if ( '| ' === $ line [0 ] ) {
231287 $ candidate = substr ( $ line , 2 );
232- $ trimmed = trim ( $ candidate );
233- // Only take lines that look like tags
234- // At least 3 chars (< + tag + >)
235- // Tag must start with ascii alphabetic
236- if ( strlen ( $ trimmed > 2 ) && '< ' === $ trimmed [0 ] && ctype_alpha ( $ trimmed [1 ] ) ) {
237- $ test_dom .= $ candidate ;
238- }
288+ // $trimmed = trim( $candidate );
289+ // // Only take lines that look like tags
290+ // // At least 3 chars (< + tag + >)
291+ // // Tag must start with ascii alphabetic
292+ // if ( strlen( $trimmed > 2 ) && '<' === $trimmed[0] && ctype_alpha( $trimmed[1] ) ) {
293+ $ test_dom .= $ candidate ;
294+ // }
239295 }
240296 break ;
241297 }
0 commit comments