-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Image: Avoid link class loss when pasting for raw transformation #67803
Conversation
Size Change: +8 B (0%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
Flaky tests detected in 56877d0. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12262213511
|
@@ -59,6 +59,7 @@ const schema = ( { phrasingContentSchema } ) => ( { | |||
...imageSchema, | |||
a: { | |||
attributes: [ 'href', 'rel', 'target' ], | |||
classes: [ /[\w-]*/ ], |
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.
Maybe we should support a wildcard matcher in cleanNodeList
for class
. There's already support for it for children
property.
gutenberg/packages/dom/src/dom/clean-node-list.js
Lines 109 to 112 in 467e4a2
// Do not filter any content. | |
if ( children === '*' ) { | |
return; | |
} |
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.
Here's the follow-up #67830.
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @designsimply. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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 #67830 is just a proposal; not sure if the wildcard support is needed there yet. Only created it to open the conversation. |
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.
LGTM! Japanese characters and emojis also seem to work correctly:
<figure class="wp-block-image size-large">
<a class="test-link hey --what test_link &<> あああ 😄" href="https://bbc.com">
<img src="https://s.w.org/patterns/files/2021/06/image-from-rawpixel-id-539759-jpeg-1-1024x1024.jpg" alt="Vintage Cupid Illustration" class="wp-image-179"/>
</a>
</figure>
Nit: Removing the hyphen from the regex pattern appears to be fine.
diff --git a/packages/block-library/src/image/transforms.js b/packages/block-library/src/image/transforms.js
index 32824c372e..207f647b4a 100644
--- a/packages/block-library/src/image/transforms.js
+++ b/packages/block-library/src/image/transforms.js
@@ -59,7 +59,7 @@ const schema = ( { phrasingContentSchema } ) => ( {
...imageSchema,
a: {
attributes: [ 'href', 'rel', 'target' ],
- classes: [ /[\w-]*/ ],
+ classes: [ /[\w]*/ ],
children: imageSchema,
},
figcaption: {
In my tests, it breaks hyphenated classes. You can do a quick Regex test on https://regex101.com. |
…dPress#67803) Unlinked contributors: designsimply. Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: paaljoachim <paaljoachim@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: greatislander <greatislander@git.wordpress.org>
What?
Fixes #11995.
PR updates the Image block's raw transformation schema to support link classes. This prevents content loss when pasting an image.
Users can edit these classes using Link UI. See #7771.
Testing Instructions
Test image HTML
Testing Instructions for Keyboard
Same.
Screenshot