Skip to content

Commit 5b8e0ec

Browse files
committed
HTML API: Add support for IN COLUMN GROUP parsing.
As part of work to add more spec support to the HTML API, this patch adds support for the IN COLUMN GROUP insertion mode. This small section of the spec handles rules for the `<colgroup>` element. Developed in WordPress#7042 Discussed in https://core.trac.wordpress.org/ticket/61576 Props: dmsnell, jonsurrell. See #61576. git-svn-id: https://develop.svn.wordpress.org/trunk@58839 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d056671 commit 5b8e0ec

File tree

1 file changed

+99
-2
lines changed

1 file changed

+99
-2
lines changed

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@ private function step_in_caption(): bool {
30683068
* This internal function performs the 'in column group' insertion mode
30693069
* logic for the generalized WP_HTML_Processor::step() function.
30703070
*
3071-
* @since 6.7.0 Stub implementation.
3071+
* @since 6.7.0
30723072
*
30733073
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
30743074
*
@@ -3078,7 +3078,104 @@ private function step_in_caption(): bool {
30783078
* @return bool Whether an element was found.
30793079
*/
30803080
private function step_in_column_group(): bool {
3081-
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP . ' state.' );
3081+
$token_name = $this->get_token_name();
3082+
$token_type = $this->get_token_type();
3083+
$op_sigil = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : '';
3084+
$op = "{$op_sigil}{$token_name}";
3085+
3086+
switch ( $op ) {
3087+
/*
3088+
* > A character token that is one of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF),
3089+
* > U+000C FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
3090+
*/
3091+
case '#text':
3092+
$text = $this->get_modifiable_text();
3093+
if ( '' === $text ) {
3094+
/*
3095+
* If the text is empty after processing HTML entities and stripping
3096+
* U+0000 NULL bytes then ignore the token.
3097+
*/
3098+
return $this->step();
3099+
}
3100+
3101+
if ( strlen( $text ) === strspn( $text, " \t\n\f\r" ) ) {
3102+
// Insert the character.
3103+
$this->insert_html_element( $this->state->current_token );
3104+
return true;
3105+
}
3106+
3107+
goto in_column_group_anything_else;
3108+
break;
3109+
3110+
/*
3111+
* > A comment token
3112+
*/
3113+
case '#comment':
3114+
case '#funky-comment':
3115+
case '#presumptuous-tag':
3116+
$this->insert_html_element( $this->state->current_token );
3117+
return true;
3118+
3119+
/*
3120+
* > A DOCTYPE token
3121+
*/
3122+
case 'html':
3123+
// @todo Indicate a parse error once it's possible.
3124+
return $this->step();
3125+
3126+
/*
3127+
* > A start tag whose tag name is "html"
3128+
*/
3129+
case '+HTML':
3130+
return $this->step_in_body();
3131+
3132+
/*
3133+
* > A start tag whose tag name is "col"
3134+
*/
3135+
case '+COL':
3136+
$this->insert_html_element( $this->state->current_token );
3137+
$this->state->stack_of_open_elements->pop();
3138+
return true;
3139+
3140+
/*
3141+
* > An end tag whose tag name is "colgroup"
3142+
*/
3143+
case '-COLGROUP':
3144+
if ( ! $this->state->stack_of_open_elements->current_node_is( 'COLGROUP' ) ) {
3145+
// @todo Indicate a parse error once it's possible.
3146+
return $this->step();
3147+
}
3148+
$this->state->stack_of_open_elements->pop();
3149+
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
3150+
return true;
3151+
3152+
/*
3153+
* > An end tag whose tag name is "col"
3154+
*/
3155+
case '-COL':
3156+
// Parse error: ignore the token.
3157+
return $this->step();
3158+
3159+
/*
3160+
* > A start tag whose tag name is "template"
3161+
* > An end tag whose tag name is "template"
3162+
*/
3163+
case '+TEMPLATE':
3164+
case '-TEMPLATE':
3165+
return $this->step_in_head();
3166+
}
3167+
3168+
in_column_group_anything_else:
3169+
/*
3170+
* > Anything else
3171+
*/
3172+
if ( ! $this->state->stack_of_open_elements->current_node_is( 'COLGROUP' ) ) {
3173+
// @todo Indicate a parse error once it's possible.
3174+
return $this->step();
3175+
}
3176+
$this->state->stack_of_open_elements->pop();
3177+
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
3178+
return $this->step( self::REPROCESS_CURRENT_NODE );
30823179
}
30833180

30843181
/**

0 commit comments

Comments
 (0)