Skip to content

Commit c2f562d

Browse files
committed
Fix void tag indenting
1 parent a592d18 commit c2f562d

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,20 @@ public static function build_html5_treelike_string( $fragment_context, $html ) {
138138

139139
switch ( $p->get_token_type() ) {
140140
case '#tag':
141+
$tag_name = strtolower( $p->get_tag() );
142+
141143
if ( $p->is_tag_closer() ) {
142144
--$indent_level;
143145
break;
144146
}
145147

146-
$indent_level = count( $p->get_breadcrumbs() );
148+
$tag_indent = count( $p->get_breadcrumbs() ) - 1;
147149

148-
$tag_name = strtolower( $p->get_tag() );
149-
$output .= str_repeat( $indent, $indent_level - 1 ) . "<{$tag_name}>\n";
150+
if ( ! WP_HTML_Processor::is_void( $tag_name ) ) {
151+
$indent_level = $tag_indent + 1;
152+
}
153+
154+
$output .= str_repeat( $indent, $tag_indent ) . "<{$tag_name}>\n";
150155

151156
$attribute_names = $p->get_attribute_names_with_prefix( '' );
152157
if ( $attribute_names ) {
@@ -161,9 +166,10 @@ public static function build_html5_treelike_string( $fragment_context, $html ) {
161166
if ( true === $val ) {
162167
$val = '';
163168
}
164-
$output .= str_repeat( $indent, $indent_level ) . "{$attribute_name}=\"{$val}\"\n";
169+
$output .= str_repeat( $indent, $tag_indent + 1 ) . "{$attribute_name}=\"{$val}\"\n";
165170
}
166171
}
172+
167173
break;
168174

169175
case '#text':

0 commit comments

Comments
 (0)