-
Notifications
You must be signed in to change notification settings - Fork 0
HTML API: Active formatting element reconstruction Noah's Ark #24
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
base: html-api/improve-active-element-reconstruction
Are you sure you want to change the base?
HTML API: Active formatting element reconstruction Noah's Ark #24
Conversation
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
|
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 Core Committers: Use this line as a base for the props when committing in SVN: 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 ) ); |
There was a problem hiding this comment.
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.
| $token_hash = $this->get_token_hash( $token, $token_html ); | ||
| $existing_count = 0; | ||
| for ( $i = count( $this->hash_stack ) - 1; $i >= 0; $i-- ) { |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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.
| $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 ) ) { |
There was a problem hiding this comment.
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.
de92777 to
88b4ca4
Compare
This is an idea to build on WordPress#6982 correctly implementing the Noah's Ark (max 3 equivalent active formatting elements).
For example:
Correctly produces:
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.