-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ToC: adapt to rich text value #57093
Conversation
) | ||
headingAttributes.content | ||
.toString() | ||
.replace( /(<br *\/?>)+/g, ' ' ) |
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.
We could actually use headingAttributes.content.toPlainText
as well now, then replace all \n
with spaces. But right now we cannot absolutely guarantee that it will be a rich text value, I need to make a PR for that.
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.
I'm torn here because this code is already doing the very thing we don't want to do: treat HTML as a string and perform risky parsing on it.
while it was the case before that the content
attribute was a string, it was still an HTML string, so we could have found a RichText
way to extract the plaint text content.
in this specific case I'd rather we use toPlainText()
and then ponder what to do about stringly-based code. for example, maybe adding the string methods only helps to perpetuate problems like this that are essentially longstanding type errors. having things crash early in the release cycle gives us a chance to update dependent code so that it remains more resilient in the future.
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.
The only reason why we'd add those methods would be to avoid errors
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.
more than simply call .toString()
do we need to wrap all these in RichTextData.from( headingAttributes.content )
?
for PRs like this we could then directly modify the content, and perform more semantic operations like .removeTags( 'br' )
, or at a minimum call .toString()
after jumping back into the RichText
world
Size Change: +10 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Flaky tests detected in 5b0a574. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7219049567
|
Updated the description to reference #43204 |
Btw, I also linked the wrong PRs, thinking it was in the GB repo. Fixed now to: wordpress-mobile/gutenberg-mobile#6462 |
Fixed in #57322. |
What?
Fixes the ToC to work with the rich text value (quick fix). See #43204 for the breaking change.
Together with wordpress-mobile/gutenberg-mobile#6462, it makes me wonder if we should add all the string methods as a compatibility layer. Cc @dmsnell.
Why?
How?
Testing Instructions
There's probably a few way to test, but here what I did:
Testing Instructions for Keyboard
Screenshots or screencast