Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML API: Handle parsing changes in foreign content. #6006

Closed
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
68a6b4a
HTML API: Add support for SVG and MathML (Foreign content)
dmsnell Jul 30, 2024
85df3a3
Update test runner
dmsnell Jul 30, 2024
47f60fe
Lower-case tag names for foreign content in test runner.
dmsnell Jul 30, 2024
c216604
Use the namespace-adjusted tag name in tests.
dmsnell Jul 30, 2024
758d5b5
Merge branch 'trunk' into html-api/detect-foreign-content
dmsnell Jul 31, 2024
83db8f0
Various updates and changes. Currently experiencing infinite loops.
dmsnell Jul 31, 2024
0cdf0da
Prevent infinite loop.
dmsnell Jul 31, 2024
f9ac6d7
Check namespace against actual token, not Tag Processor state.
dmsnell Aug 1, 2024
c753249
Provide method for getting adjusted attribute names, and update testi…
dmsnell Aug 1, 2024
5bb9eb1
HTML5Lib: Prevent printing empty text nodes in tree
sirreal Aug 1, 2024
974c45a
phpcs fix
sirreal Aug 1, 2024
56ba291
Closing BR can occur outside of the HTML namespace.
dmsnell Aug 1, 2024
047825b
Fix an issue with mathml integration point check
sirreal Aug 5, 2024
28816c7
Change parsing namespace in push/pop handlers
sirreal Aug 5, 2024
3eb0654
Check for namespace in expects_closer atomic elements
sirreal Aug 5, 2024
5a64823
Use insert_foreign_element to insert foreign elements
sirreal Aug 5, 2024
31801d6
Do not report foreign content self-closing tags as closers
sirreal Aug 6, 2024
f66ba57
Fix typo in femorphology tag name
sirreal Aug 6, 2024
efbf5ef
Merge branch 'trunk' into html-api/detect-foreign-content
sirreal Aug 7, 2024
32c25d5
Fix svg:TEMPLATE handling in html5lib tests
sirreal Aug 7, 2024
9e0b884
Fix HTML5lib-test handling of self-closing tags
sirreal Aug 7, 2024
71cd1b2
Only transform attributes outside of html namespace
sirreal Aug 6, 2024
2a3f6cb
Use get_namespace() over parsing_namespace
sirreal Aug 6, 2024
0f94dcb
Use get_adjusted_current_node when getting namespace
sirreal Aug 6, 2024
e90fbc3
Fix adjusted_current_node to check _element_ nodes
sirreal Aug 6, 2024
00f9b68
More passing FC tests
sirreal Aug 6, 2024
58be2d8
Do not need to worry about those elements after all
sirreal Aug 7, 2024
9a83dc7
Move namespace handling into insert_foriegn_element
sirreal Aug 7, 2024
e004603
Handle namespace mucking inside "insert_foreign_element"
sirreal Aug 7, 2024
641e678
Revert "Handle namespace mucking inside "insert_foreign_element""
sirreal Aug 7, 2024
c944b1b
Revert "Move namespace handling into insert_foriegn_element"
sirreal Aug 7, 2024
0056d2f
Revert irrelevant change
sirreal Aug 7, 2024
781df79
Reapply "Move namespace handling into insert_foriegn_element"
sirreal Aug 7, 2024
64e3e5d
Reapply "Handle namespace mucking inside "insert_foreign_element""
sirreal Aug 7, 2024
4e6407e
Only insert foreign elements when handling foreign content
sirreal Aug 7, 2024
ce86164
Do not change the namespace to the integration node type
sirreal Aug 7, 2024
6afdbe6
Update comments, reorder `try`, support SCRIPT tags.
dmsnell Aug 8, 2024
a1e48e3
Revert change to BR closing tag behavior.
dmsnell Aug 8, 2024
8f01a18
Rename "namespaced" tag/attribute name getters to "get_qualified_...()"
dmsnell Aug 8, 2024
2016cc4
WPCS
dmsnell Aug 8, 2024
657df3b
New TODO ear-marking a logic review.
dmsnell Aug 8, 2024
57e8670
Move the foreign content other end tag label into condition
sirreal Aug 8, 2024
38aab38
Merge remote-tracking branch 'upstream/trunk' into html-api/detect-fo…
dmsnell Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 61 additions & 44 deletions src/wp-includes/html-api/class-wp-html-open-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,22 @@ public function current_node_is( string $identity ): bool {
*/
public function has_element_in_specific_scope( string $tag_name, $termination_list ): bool {
foreach ( $this->walk_up() as $node ) {
if ( $node->node_name === $tag_name ) {
$namespaced_name = 'html' === $node->namespace
? $node->node_name
: "{$node->namespace} {$node->node_name}";

if ( $namespaced_name === $tag_name ) {
return true;
}

if (
'(internal: H1 through H6 - do not use)' === $tag_name &&
in_array( $node->node_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true )
in_array( $namespaced_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true )
) {
return true;
}

if ( in_array( $node->node_name, $termination_list, true ) ) {
if ( in_array( $namespaced_name, $termination_list, true ) ) {
return false;
}
}
Expand Down Expand Up @@ -288,7 +292,7 @@ public function has_element_in_specific_scope( string $tag_name, $termination_li
* > - SVG title
*
* @since 6.4.0
* @since 6.7.0 Supports all required HTML elements.
* @since 6.7.0 Full support.
*
* @see https://html.spec.whatwg.org/#has-an-element-in-scope
*
Expand All @@ -309,19 +313,16 @@ public function has_element_in_scope( string $tag_name ): bool {
'OBJECT',
'TEMPLATE',

/*
* @todo Support SVG and MathML nodes when support for foreign content is added.
*
* - MathML mi
* - MathML mo
* - MathML mn
* - MathML ms
* - MathML mtext
* - MathML annotation-xml
* - SVG foreignObject
* - SVG desc
* - SVG title
*/
'math MI',
'math MO',
'math MN',
'math MS',
'math MTEXT',
'math ANNOTATION-XML',

'svg FOREIGNOBJECT',
'svg DESC',
'svg TITLE',
)
);
}
Expand Down Expand Up @@ -363,19 +364,16 @@ public function has_element_in_list_item_scope( string $tag_name ): bool {
'TEMPLATE',
'UL',

/*
* @todo Support SVG and MathML nodes when support for foreign content is added.
*
* - MathML mi
* - MathML mo
* - MathML mn
* - MathML ms
* - MathML mtext
* - MathML annotation-xml
* - SVG foreignObject
* - SVG desc
* - SVG title
*/
'math MI',
'math MO',
'math MN',
'math MS',
'math MTEXT',
'math ANNOTATION-XML',

'svg FOREIGNOBJECT',
'svg DESC',
'svg TITLE',
)
);
}
Expand Down Expand Up @@ -413,19 +411,16 @@ public function has_element_in_button_scope( string $tag_name ): bool {
'OBJECT',
'TEMPLATE',

/*
* @todo Support SVG and MathML nodes when support for foreign content is added.
*
* - MathML mi
* - MathML mo
* - MathML mn
* - MathML ms
* - MathML mtext
* - MathML annotation-xml
* - SVG foreignObject
* - SVG desc
* - SVG title
*/
'math MI',
'math MO',
'math MN',
'math MS',
'math MTEXT',
'math ANNOTATION-XML',

'svg FOREIGNOBJECT',
'svg DESC',
'svg TITLE',
)
);
}
Expand Down Expand Up @@ -692,11 +687,15 @@ public function walk_up( ?WP_HTML_Token $above_this_node = null ) {
* @param WP_HTML_Token $item Element that was added to the stack of open elements.
*/
public function after_element_push( WP_HTML_Token $item ): void {
$namespaced_name = 'html' === $item->namespace
? $item->node_name
: "{$item->namespace} {$item->node_name}";

/*
* When adding support for new elements, expand this switch to trap
* cases where the precalculated value needs to change.
*/
switch ( $item->node_name ) {
switch ( $namespaced_name ) {
case 'APPLET':
case 'BUTTON':
case 'CAPTION':
Expand All @@ -707,6 +706,15 @@ public function after_element_push( WP_HTML_Token $item ): void {
case 'MARQUEE':
case 'OBJECT':
case 'TEMPLATE':
case 'math MI':
case 'math MO':
case 'math MN':
case 'math MS':
case 'math MTEXT':
case 'math ANNOTATION-XML':
case 'svg FOREIGNOBJECT':
case 'svg DESC':
case 'svg TITLE':
$this->has_p_in_button_scope = false;
break;

Expand Down Expand Up @@ -750,6 +758,15 @@ public function after_element_pop( WP_HTML_Token $item ): void {
case 'MARQUEE':
case 'OBJECT':
case 'TEMPLATE':
case 'math MI':
case 'math MO':
case 'math MN':
case 'math MS':
case 'math MTEXT':
case 'math ANNOTATION-XML':
case 'svg FOREIGNOBJECT':
case 'svg DESC':
case 'svg TITLE':
$this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' );
break;
}
Expand Down
12 changes: 0 additions & 12 deletions src/wp-includes/html-api/class-wp-html-processor-state.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,6 @@ class WP_HTML_Processor_State {
*/
const INSERTION_MODE_AFTER_AFTER_FRAMESET = 'insertion-mode-after-after-frameset';

/**
* In foreign content insertion mode for full HTML parser.
*
* @since 6.7.0
*
* @see https://html.spec.whatwg.org/#parsing-main-inforeign
* @see WP_HTML_Processor_State::$insertion_mode
*
* @var string
*/
const INSERTION_MODE_IN_FOREIGN_CONTENT = 'insertion-mode-in-foreign-content';

/**
* No-quirks mode document compatability mode.
*
Expand Down
Loading
Loading