Skip to content

Conversation

@sirreal
Copy link
Collaborator

@sirreal sirreal commented Dec 2, 2025

This is an idea to build on WordPress#6982 correctly implementing the Noah's Ark (max 3 equivalent active formatting elements).

For example:

<div>
<i>
<i>
<i>
<i>
<i 1 2>
<i 2 1>
<i 1="" 2>
<i 2="" 1=>
</div>x

Correctly produces:

├─DIV
│ ├─#text  
│ └─I
│   ├─#text  
│   └─I
│     ├─#text  
│     └─I
│       ├─#text  
│       └─I
│         ├─#text  
│         └─I 1="" 2=""
│           ├─#text  
│           └─I 2="" 1=""
│             ├─#text  
│             └─I 1="" 2=""
│               ├─#text  
│               └─I 2="" 1=""
│                 └─#text  
└─I
  └─I
    └─I
      └─I 2="" 1=""
        └─I 1="" 2=""
          └─I 2="" 1=""
            └─#text x

Note that the correct items are pruned. The most recent additions are supposed to be maintained and equivalent items already on the stack are removed.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

The Block Processor tests call `NumberFormatter` for generating its
error messages, but in environments lacking the `intl` extension this
led to crashes while running the tests.

This patch reworks the tests so that they avoid calling
`NumberFormatter` so that the tests run on more diverse setups.

Developed in WordPress#10576
Discussed in https://core.trac.wordpress.org/ticket/64329

Follow-up to [60939].

Props desrosj, ellatrix, peterwilsoncc, westonruter.

See #64329.


git-svn-id: https://develop.svn.wordpress.org/trunk@61342 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions
Copy link

github-actions bot commented Dec 2, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dmsnell, jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

}
$hash_string .= '>';

return dechex( crc32( $hash_string ) );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't require hashing, the strings could be compared directly.

The strings with attributes risk getting quite long, the hash could be skipped for a simpler representation if there are no attributes.

Comment on lines +203 to +205
$token_hash = $this->get_token_hash( $token, $token_html );
$existing_count = 0;
for ( $i = count( $this->hash_stack ) - 1; $i >= 0; $i-- ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this work could be skipped if the stack is smaller than 3 or if the stack up to the last marker is smaller than three. In those cases there's no chance that something needs to be removed.

// @todo Implement removing the earliest element and moving forward.
return false;
}
$token_hash = $this->get_token_hash( $token, $token_html );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be represented in another way, perhaps:

[ "namespace", "tag_name", "attrs_hash"|null ]

The most costly part (making a way to correctly compare attributes) could be done lazily.

That's difficult because this class doesn't have access to the underlying HTML or the processor.

Comment on lines +2781 to +2783
$bookmark = $this->bookmarks[ $this->state->current_token->bookmark_name ];
$token_html = substr( $this->html, $bookmark->start, $bookmark->length );
if ( false === $this->state->active_formatting_elements->push( $this->state->current_token, $token_html ) ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's annoying, but it may be essential to compare attributes. The active formatting elements class doesn't have a good way to access attributes at this time.

@sirreal sirreal force-pushed the html-api/try-noahs-ark-of-3 branch from de92777 to 88b4ca4 Compare December 2, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants