48906 Commits

Author SHA1 Message Date
Riad Benguella
9453f3a85b Editor: Update WordPress packages to Gutenberg 16.7 RC3.
It brings with a set of iterations and follow-ups to the initial package update.
It also fixes a regression that happened for interactive blocks.

Props gziolo, luisherranz, cbravobernal.
See #60315.

git-svn-id: https://develop.svn.wordpress.org/trunk@57499 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 11:54:09 +00:00
Riad Benguella
38ff9709b2 Editor: Fix Theme.json font settings unit test.
This file has been ommitted from the previous commit [57497].

See #60341.

git-svn-id: https://develop.svn.wordpress.org/trunk@57498 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 11:36:44 +00:00
Riad Benguella
621ac049c6 Editor: Fix Theme.json font settings in unit test.
These changes fix incorrect font settings when testing the generation of a theme.json stylesheet.

Props aaronrobertshaw, mukesh27.
Fixes #60341.

git-svn-id: https://develop.svn.wordpress.org/trunk@57497 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 10:59:33 +00:00
Riad Benguella
b999860bb6 Editor: Sanitize nested array in theme.json properly.
WP_Theme_JSON sanitization is now able to sanitize data contained on indexed arrays. 
So certain data from theme.json, for example, settings.typography.fontFamilies which is a JSON array will be sanitized.

Props mmaattiiaass, mukesh27.
Fixes #60360.

git-svn-id: https://develop.svn.wordpress.org/trunk@57496 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 10:53:48 +00:00
Sergey Biryukov
4472385b88 Twenty Eleven: Fix typo in twentyeleven_widgets_init() description.
Follow-up to [17738].

Props harshgajipara.
See #60383.

git-svn-id: https://develop.svn.wordpress.org/trunk@57495 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 10:50:33 +00:00
Riad Benguella
c45f527fbd REST API: Add route for single styles revisions.
Adds a route for single global styles revisions: /wp/v2/global-styles/${ parentId }/revisions/${ revisionsId }
This fixes the `getRevision` actions in the core-data package.

Props ramonopoly, get_dave.
Fixes #59810.

git-svn-id: https://develop.svn.wordpress.org/trunk@57494 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 10:39:04 +00:00
Greg Ziółkowski
1a5ff3fc6d Editor: Add viewStyle property to block.json for frontend-only block styles
Related issue in Gutenberg: https://github.com/WordPress/gutenberg/issues/54491.

For block scripts there was already `script`, `viewScript` and `editorScript`. For block styles there was only `style` and `editorStyle`. This brings the parity.

Props gaambo.
Fixes #59673. 



git-svn-id: https://develop.svn.wordpress.org/trunk@57493 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 09:09:22 +00:00
Greg Ziółkowski
dc15d66ee6 Script Modules API: Add import map polyfill for older browsers
Syncs the changes from https://github.com/WordPress/gutenberg/pull/58263. Adds a polyfill to make import maps compatible with unsported browsers (https://caniuse.com/import-maps).

Fixes #60348.
Props cbravobernal, jorbin, luisherranz, jonsurrell.



git-svn-id: https://develop.svn.wordpress.org/trunk@57492 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 08:29:18 +00:00
Isabel Brison
5d3f66ac5b Editor: introduce dimensions.aspectRatio block support.
Adds front end rendering logic for the `dimensions.aspectRatio` block support as well as the required logic in `WP_Theme_JSON` and the style engine.

Props andrewserong.
Fixes #60365.


git-svn-id: https://develop.svn.wordpress.org/trunk@57491 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 02:52:25 +00:00
Isabel Brison
5a59dbed82 Editor: reduce specificity of block style variation selector.
Removes duplicate classname from the block style variation selector generated in `WP_Theme_JSON`’s `get_blocks_metadata` function.

Props flixos90, joemcgill, mukesh27, isabel_brison.
Fixes #60312.


git-svn-id: https://develop.svn.wordpress.org/trunk@57490 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 23:49:09 +00:00
Dennis Snell
0b800d7e58 HTML API: Fix splitting single text node.
When `next_token()` was introduced, it brought a subtle bug. When encountering a `<` in the HTML stream which did not lead to a tag or comment or other token, it was treating the full text span to that point as one text node, and the following span another text node.

The entire span should be one text node.

In this patch the Tag Processor properly detects this scenario and combines the spans into one text node.

Follow-up to [57348]

Props jonsurrell
Fixes #60385



git-svn-id: https://develop.svn.wordpress.org/trunk@57489 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 22:07:42 +00:00
Aaron Jorbin
a172e31c9e Install: When populating options, maybe_serialize instead of always serialize.
Props xknown, peterwilsoncc, jorbin, desrosj.


git-svn-id: https://develop.svn.wordpress.org/trunk@57389 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 14:23:06 +00:00
Aaron Jorbin
9573b33d97 Uploads: Check for and verify ZIP archives.
Props costdev, peterwilsoncc, azaozz, tykoted, johnbillion, desrosj, afragen, jorbin.


git-svn-id: https://develop.svn.wordpress.org/trunk@57388 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 14:21:47 +00:00
Pascal Birchler
3e9263588d I18N: Add missing space after foreach keyword.
Follow-up to [57386].

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57387 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 14:08:20 +00:00
Pascal Birchler
71b8dcb08c I18N: Improve singular lookup of pluralized strings.
Ensures that looking up a singular that is also used as a pluralized string works as expected.
This improves compatibility for cases where for example both `__( 'Product' )` and `_n( 'Product', 'Products’, num )` are used in a project, where both will use the same translation for the singular version.

Although such usage is not really recommended nor documented, it must continue to work in the new i18n library in order to maintain backward compatibility and maintain expected behavior.

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57386 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 13:59:46 +00:00
Greg Ziółkowski
cabfa6f52c Tests: Remove redundant unregister call in block bindings tear down
Only block bindings sources registered in the tests should get unregistered.

Follow-up for [57375].
See #60282.
Props czapla.



git-svn-id: https://develop.svn.wordpress.org/trunk@57385 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 12:55:53 +00:00
Riad Benguella
a9c985cde4 Editor: Update the minimum compatible version of Gutenberg.
Previous Gutenberg versions are not compatible with recent trunk because of the
WP_Navigation_Block_Renderer classname. It's present in both.

Gutenberg has been updated to avoid the use of this class but we need to auto-disable 
old plugins to avoid fatals.

Props hellofromtonya.
See #60315.

git-svn-id: https://develop.svn.wordpress.org/trunk@57384 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 11:39:14 +00:00
Riad Benguella
5466d3a9a7 Editor: Fix PHP warning in Layout block support.
strpos was triggering a php warning. 
This also updates the code to use the now supported str_contains.

Props get_dave, dmsnell, ocean90, mukesh27.
Fixes #60327.

git-svn-id: https://develop.svn.wordpress.org/trunk@57383 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 11:08:15 +00:00
Pascal Birchler
b57c822afd I18N: Delete .l10n.php files when deleting a theme.
Follow-up to [57337] where this was already added for plugins.

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57382 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 10:31:00 +00:00
Pascal Birchler
179b6807b8 I18N: Ensure .l10n.php files are deleted when upgrading language packs.
Props amieiro.
See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57381 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 10:28:54 +00:00
Pascal Birchler
0e0b10092c REST API: Support assigning terms when creating attachments.
Props mukesh27, Dharm1025, Ankit K Gupta, swissspidy, dharm1025, tanjimtc71, timothyblynjacobs, spacedmonkey.
Fixes #57897.

git-svn-id: https://develop.svn.wordpress.org/trunk@57380 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 08:37:04 +00:00
Jonathan Desrosiers
94e6fe9f8a Build/Test Tools: Test against MySQL 8.3
Version 8.3 is the latest short-term innovation release of MySQL.

See #59779.

git-svn-id: https://develop.svn.wordpress.org/trunk@57379 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 00:32:50 +00:00
Sergey Biryukov
90ad304486 Coding Standards: Update PHPCS to version 3.8.1.
PHPCS has seen two new releases since the update to WPCS 3.0, with especially the 3.8.0 version containing a huge number of improvements.

References:
* [https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.8.0 PHP_CodeSniffer 3.8.0 release notes]
* [https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.8.1 PHP_CodeSniffer 3.8.1 release notes]

Follow-up to [56695].

Props jrf, swissspidy.
Fixes #60279.

git-svn-id: https://develop.svn.wordpress.org/trunk@57378 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-29 21:29:52 +00:00
Riad Benguella
cf8b74de16 Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress. 
This includes features like:

 - DataViews.
 - Customization tools like box shadow, background size and repeat.
 - UI improvements in the site editor. 
 - Preferences sharing between the post and site editors.
 - Unified panels and editors between post and site editors.
 - Improved template mode in the post editor.
 - Iterations to multiple interactive blocks.
 - Preparing the blocks and UI for pattern overrides.
 - and a lot more.

Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.

git-svn-id: https://develop.svn.wordpress.org/trunk@57377 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-29 21:04:18 +00:00
Jonathan Desrosiers
393f67387f Build/Test Tools: Update third-party Slack action.
This updates the `slackapi/slack-github-action` from `1.24.0` to `1.25.0`. This fixes more GitHub Action deprecated notices.

Follow up to [57362].

See #59805.

git-svn-id: https://develop.svn.wordpress.org/trunk@57376 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-29 15:04:27 +00:00
Greg Ziółkowski
2ce87aa6f5 Editor: Add Block Bindings API helpers
It is part of the sync from the Gutenberg plugin that introduces the registry for block binding sources required for the new Block Bindings API: WordPress/gutenberg#54536.

See #60282.
Follow-up [57373].
Props czapla, artemiosans, santosguillamot, sc0ttkclark, lgladdy, talldanwp, swissspidy, youknowriad, fabiankaegy, mukesh27.



git-svn-id: https://develop.svn.wordpress.org/trunk@57375 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-29 13:06:09 +00:00
Jorge Costa
9b0d0af28b Coding Standards: Remove unnecessary access and internal annotations from two functions in WP_REST_Templates_Controller.
This commit removes unnecessary access and internal annotations from two functions that are private and as such don't require the annotation. It also adds the since annotation with the 6.5 release given that the annotation may be useful.

Props swissspidy.
See #60358.

git-svn-id: https://develop.svn.wordpress.org/trunk@57374 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-29 12:32:26 +00:00
Greg Ziółkowski
adbd348633 Editor: Add registry for block binding sources
It is part of the sync from the Gutenberg plugin that introduces the registry for block binding sources required for the new Block Bindings API: https://github.com/WordPress/gutenberg/issues/54536.

See #60282.
Props czapla, artemiosans, santosguillamot, sc0ttkclark, lgladdy, talldanwp, swissspidy, youknowriad, fabiankaegy.



git-svn-id: https://develop.svn.wordpress.org/trunk@57373 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-29 11:14:22 +00:00
Sergey Biryukov
e108d27762 Coding Standards: Use strict type check for in_array() in get_hooked_block_markup().
This aims to prevent type juggling causing incorrect results.

Follow-up to [57157].

Props jrf.
See #60279.

git-svn-id: https://develop.svn.wordpress.org/trunk@57372 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-28 21:33:00 +00:00
Jb Audras
c786aa8abf Docs: Typo correction in wp_internal_hosts docblock.
Follow-up to [55289].

Props shailu25.
Fixes #60363.





git-svn-id: https://develop.svn.wordpress.org/trunk@57371 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-28 16:38:10 +00:00
Jb Audras
c8e4c33fc2 Docs: Improve various globals documentation, as per docblock standards.
Props upadalavipul, audrasjb, shailu25, viralsampat.
Fixes #59255.
See #59651.





git-svn-id: https://develop.svn.wordpress.org/trunk@57370 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-28 08:17:54 +00:00
Jb Audras
a9e47699a7 Coding Standards: Add missing escaping functions to WP_Customize_Control and WP_Customize_Nav_Menu_Location_Control.
Follow-up to [20295], [32806].

Props nareshbheda, shailu25, sabernhardt, audrasjb.
Fixes #60324.





git-svn-id: https://develop.svn.wordpress.org/trunk@57369 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-28 07:48:15 +00:00
Sergey Biryukov
0c4cc89447 Tests: Expand sanitize_text_field() tests.
This change ensures that the `sanitize_text_field` and `sanitize_textarea_field` filters are correctly invoked for the respective functions.

Follow-up to [38944].

Props pbearne, audrasjb.
Fixes #60357.

git-svn-id: https://develop.svn.wordpress.org/trunk@57368 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-27 20:35:27 +00:00
Weston Ruter
5c4b4887bf Script Loader: Clarify in docs that wp_get_inline_script_tag() and wp_print_inline_script_tag() can take non-JS data.
Props vladimiraus.
Fixes #60331.


git-svn-id: https://develop.svn.wordpress.org/trunk@57367 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-27 01:02:35 +00:00
Jorge Costa
400a7ac31b Editor: Add original_source and author_text to the templates REST API.
For the new "All templates" UI to work properly we need the REST API to provide to additional fields original_source, and author_text.

Props ntsekouras, get_dave.
Fixes #60358.

git-svn-id: https://develop.svn.wordpress.org/trunk@57366 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-27 00:05:24 +00:00
Jorge Costa
338fb7e8da Coding Standards: Fix some spaces on block-supports background.
When we run composer format these changes are applied so I guess we should just commit them to avoid seeing the changes again the future.

git-svn-id: https://develop.svn.wordpress.org/trunk@57365 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-26 17:51:37 +00:00
Sergey Biryukov
5fbcb55986 Coding Standards: Add missing escaping in Custom_Image_Header::step_2().
Follow-up to [4673], [14907].

Props nareshbheda, audrasjb, kebbet.
Fixes #59278.

git-svn-id: https://develop.svn.wordpress.org/trunk@57364 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-26 14:18:14 +00:00
Jonathan Desrosiers
311f45e2dc Build/Test Tools: Update the caniuse data.
This updates the `caniuse-lite` database and includes all resulting CSS and built file changes, which are all minor changes due to fluctuations in browser usage.

Props gziolo, jonsurrell.
See #59657.

git-svn-id: https://develop.svn.wordpress.org/trunk@57363 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-26 14:02:47 +00:00
Jonathan Desrosiers
d7d91b8f90 Build/Test Tools: Update third-party GitHub Actions.
This updates the following third-party GitHub Actions to their latest versions:

- `actions/setup-node` from `3.8.1` to `4.0.1`
- `actions/upload-artifact` from `3.1.2` to `4.3.0`
- `shivammathur/setup-php` from `2.28.0` to `2.29.0`
- `actions/cache` from `3.3.2` to `4.0.0`
- `codecov/codecov-action` from `3.1.4` to `3.1.5`

Most notably, these updates silence newly encountered notices as a result of GitHub beginning to transition away from Node.js 16 to Node.js 20 (see https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/).

Props swissspidy.
See #59805.

git-svn-id: https://develop.svn.wordpress.org/trunk@57362 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-26 13:48:01 +00:00
Aaron Jorbin
3cb6f03541 Build/Tests: Ensure set_error_handler is cleaned up.
Follow up to: [57332].

Fixes #60305.



git-svn-id: https://develop.svn.wordpress.org/trunk@57361 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-26 00:52:39 +00:00
Aaron Jorbin
fe1df4023c Media: Redirect inactive attachment pages for logged-out users.
Ensure logged out users are redirected to the media file when attachment pages are inactive. This removes the read_post capability check from the canonical redirects as anonymous users lack the permission.

This was previously committed in [57310] before being reverted in [57318]. This update includes a fix to cover instances where revealing a URL could be considered a data leak and greatly expands the unit tests to ensure that this is covered along with many other instances.

Follow-up to [56657], [56658], [56711], [57310], [57318].

Props peterwilsoncc, jorbin, afercia, aristath, chesio, joppuyo, jorbin, lakshmananphp, poena, sergeybiryukov, swissspidy, johnbillion.
Fixes #59866.
See #57913.


git-svn-id: https://develop.svn.wordpress.org/trunk@57357 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 17:34:54 +00:00
Sergey Biryukov
bb143998dc Docs: Fix a few typos in wp-includes/pomo/po.php.
Props shailu25.
Fixes #60346.

git-svn-id: https://develop.svn.wordpress.org/trunk@57356 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 17:06:45 +00:00
bernhard-reiter
2526eab870 Block Hooks: Amend PHPDoc for hooked_block_{$hooked_block_type} filter.
Add missing explanation of the dynamic part of the hook name.

Follow-up [57354].
Props swissspidy.
See #59572, #60126.

git-svn-id: https://develop.svn.wordpress.org/trunk@57355 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 14:18:43 +00:00
bernhard-reiter
a92aa29daf Block Hooks: Introduce a new hooked_block_{$block_type} filter.
Add a new `hooked_block_{$block_type}` filter that allows modifying a hooked block (in parsed block format) prior to insertion, while providing read access to its anchor block (in the same format).

This allows block authors to e.g. set a hooked block's attributes, or its inner blocks; the filter can peruse information about the anchor block when doing so. As such, this filter provides a solution to both #59572 and #60126.

The new filter is designed to strike a good balance and separation of concerns with regard to the existing [https://developer.wordpress.org/reference/hooks/hooked_block_types/ `hooked_block_types` filter], which allows addition or removal of a block to the list of hooked blocks for a given anchor block -- all of which are identified only by their block ''types''. This new filter, on the other hand, only applies to ''one'' hooked block at a time, and allows modifying the entire (parsed) hooked block; it also gives (read) access to the parsed anchor block.

Props gziolo, tomjcafferkey, andrewserong, isabel_brison, timbroddin, yansern.
Fixes #59572, #60126.

git-svn-id: https://develop.svn.wordpress.org/trunk@57354 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 13:46:49 +00:00
Riad Benguella
1fdafcaab8 Editor: Add video and audio pattern categories.
More categories, better organization for patterns
as they grow and power more WordPress websites.

Props aaronrobertshaw, get_dave.
Fixes #60342.

git-svn-id: https://develop.svn.wordpress.org/trunk@57353 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 12:46:04 +00:00
Riad Benguella
5bd13e7cc1 Editor: Fix Theme.json application of custom root selector for styles.
Theme.json stylesheets attempting to use a custom root selector are generated with in correct styles.

Props aaronrobertshaw, get_dave, mukesh27.
Fixes #60343.

git-svn-id: https://develop.svn.wordpress.org/trunk@57352 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 10:41:38 +00:00
Pascal Birchler
b617b5c79a Twenty Twenty-Four: Change font family slug to lowercase.
Ensures referencing the correct CSS custom property.

Props RavanH, poena, onemaggie, huzaifaalmesbah, mukesh27.
Fixes #60325.

git-svn-id: https://develop.svn.wordpress.org/trunk@57351 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 09:25:32 +00:00
Pascal Birchler
a61525049f I18N: Rename WP_Translation_Controller::instance() method to get_instance().
This improves consistency as `get_instance()` is more commonly used in core. 

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57350 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 07:51:12 +00:00
Sergey Biryukov
fa441afd6e Docs: Fix typo in _get_block_template_file() DocBlock.
Follow-up to [55744].

See #59651.

git-svn-id: https://develop.svn.wordpress.org/trunk@57349 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-24 23:39:52 +00:00
Dennis Snell
616e673d3e HTML API: Scan all syntax tokens in a document, read modifiable text.
Since its introduction in WordPress 6.2 the HTML Tag Processor has
provided a way to scan through all of the HTML tags in a document and
then read and modify their attributes. In order to reliably do this, it
also needed to be aware of other kinds of HTML syntax, but it didn't
expose those syntax tokens to consumers of the API.

In this patch the Tag Processor introduces a new scanning method and a
few helper methods to read information about or from each token. Most
significantly, this introduces the ability to read `#text` nodes in the
document.

What's new in the Tag Processor?
================================

 - `next_token()` visits every distinct syntax token in a document.
 - `get_token_type()` indicates what kind of token it is.
 - `get_token_name()` returns something akin to `DOMNode.nodeName`.
 - `get_modifiable_text()` returns the text associated with a token.
 - `get_comment_type()` indicates why a token represents an HTML comment.

Example usage.
==============

{{{
<?php
function strip_all_tags( $html ) {
        $text_content = '';
        $processor    = new WP_HTML_Tag_Processor( $html );

        while ( $processor->next_token() ) {
                if ( '#text' !== $processor->get_token_type() ) {
                        continue;
                }

                $text_content .= $processor->get_modifiable_text();
        }

        return $text_content;
}
}}}

What changes in the Tag Processor?
==================================

Previously, the Tag Processor would scan the opening and closing tag of
every HTML element separately. Now, however, there are special tags
which it only visits once, as if those elements were void tags without
a closer.

These are special tags because their content contains no other HTML or
markup, only non-HTML content.

 - SCRIPT elements contain raw text which is isolated from the rest of
   the HTML document and fed separately into a JavaScript engine. There
   are complicated rules to avoid escaping the script context in the HTML.
   The contents are left verbatim, and character references are not decoded.

 - TEXTARA and TITLE elements contain plain text which is decoded
   before display, e.g. transforming `&amp;` into `&`. Any markup which
   resembles tags is treated as verbatim text and not a tag.

 - IFRAME, NOEMBED, NOFRAMES, STYLE, and XMP elements are similar to the
   textarea and title elements, but no character references are decoded.
   For example, `&amp;` inside a STYLE element is passed to the CSS engine
   as the literal string `&amp;` and _not_ as `&`.

Because it's important not treat this inner content separately from the
elements containing it, the Tag Processor combines them when scanning
into a single match and makes their content available as modifiable
text (see below).

This means that the Tag Processor will no longer visit a closing tag for
any of these elements unless that tag is unexpected.

{{{
    <title>There is only a single token in this line</title>
    <title>There are two tokens in this line></title></title>
    </title><title>There are still two tokens in this line></title>
}}}

What are tokens?
================

The term "token" here is a parsing term, which means a primitive unit in
HTML. There are only a few kinds of tokens in HTML:

 - a tag has a name, attributes, and a closing or self-closing flag.
 - a text node, or `#text` node contains plain text which is displayed
   in a browser and which is decoded before display.
 - a DOCTYPE declaration indicates how to parse the document.
 - a comment is hidden from the display on a page but present in the HTML.

There are a few more kinds of tokens that the HTML Tag Processor will
recognize, some of which don't exist as concepts in HTML. These mostly
comprise XML syntax elements that aren't part of HTML (such as CDATA and
processing instructions) and invalid HTML syntax that transforms into
comments.

What is a funky comment?
========================

This patch treats a specific kind of invalid comment in a special way.
A closing tag with an invalid name is considered a "funky comment." In
the browser these become HTML comments just like any other, but their
syntax is convenient for representing a variety of bits of information
in a well-defined way and which cannot be nested or recursive, given
the parsing rules handling this invalid syntax.

 - `</1>`
 - `</%avatar_url>`
 - `</{"wp_bit": {"type": "post-author"}}>`
 - `</[post-author]>`
 - `</__( 'Save Post' );>`

All of these examples become HTML comments in the browser. The content
inside the funky content is easily parsable, whereby the only rule is
that it starts at the `<` and continues until the nearest `>`. There
can be no funky comment inside another, because that would imply having
a `>` inside of one, which would actually terminate the first one.

What is modifiable text?
========================

Modifiable text is similar to the `innerText` property of a DOM node.
It represents the span of text for a given token which may be modified
without changing the structure of the HTML document or the token.

There is currently no mechanism to change the modifiable text, but this
is planned to arrive in a later patch.

Tags
====

Most tags have no modifiable text because they have child nodes where
text nodes are found. Only the special tags mentioned above have
modifiable text.

{{{
    <div class="post">Another day in HTML</div>
    └─ tag ──────────┘└─ text node ─────┘└────┴─ tag
}}}

{{{
    <title>Is <img> &gt; <image>?</title>
    │      └ modifiable text ───┘       │ "Is <img> > <image>?"
    └─ tag ─────────────────────────────┘
}}}

Text nodes
==========

Text nodes are entirely modifiable text.

{{{
    This HTML document has no tags.
    └─ modifiable text ───────────┘
}}}

Comments
========

The modifiable text inside a comment is the portion of the comment that
doesn't form its syntax. This applies for a number of invalid comments.

{{{
    <!-- this is inside a comment -->
    │   └─ modifiable text ──────┘  │
    └─ comment token ───────────────┘
}}}

{{{
    <!-->
    This invalid comment has no modifiable text.
}}}

{{{
    <? this is an invalid comment -->
    │ └─ modifiable text ────────┘  │
    └─ comment token ───────────────┘
}}}

{{{
    <[CDATA[this is an invalid comment]]>
    │       └─ modifiable text ───────┘ │
    └─ comment token ───────────────────┘
}}}

Other token types also have modifiable text. Consult the code or tests
for further information.

Developed in https://github.com/WordPress/wordpress-develop/pull/5683
Discussed in https://core.trac.wordpress.org/ticket/60170

Follows [57575]

Props bernhard-reiter, dlh, dmsnell, jonsurrell, zieladam
Fixes #60170



git-svn-id: https://develop.svn.wordpress.org/trunk@57348 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-24 23:35:46 +00:00