-
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
Fix converting caption shortcode with link #12315
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.
Hi @iseulde this generally worked correctly in my tests. I think there is only one attribute missing from this conversion. We are not setting the linkDestination attribute.
So for example, when I convert the following data:
[caption id="attachment_6" align="alignnone" width="300"]<a href="http://www.example.com"><img class="wp-image-6 size-medium" src="http://enchanting-caterpillar.w5.poopy.life/wp-content/uploads/2018/11/Nov-15-2018-12-08-48-300x240.gif" alt="" width="300" height="240" /></a> aaaaa[/caption]
The link to field goes from "Custom URL" in the classic editor to "None" but if I change "Link to" to custom URL to correct custom link appears.
I think we're missing a few more attributes as well:
|
@alexsanford Did you mean custom width and height? I verified the missing link to the media file, but I choose a large size which appeared to transfer over on block conversion. |
@gwwar Yeah, the custom width and height attributes on the |
Note that captions can contain arbitrary html |
What is |
@iseulde Looks like you beat me :) taking this for another spin. |
How do we source it from the example here: |
Manually tests well with plain captions, and captions with links and styling 👍 . The missing link settings is maybe a separate issue. I'd be okay with a follow up PR if this isn't the right spot to modify that. |
We'd need to get the media and attachment link from the ID, then compare it. I agree that this can be a separate PR. |
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.
Thanks @iseulde, let's go with this then! Do you mind adding another issue for the follow up bug, if we don't have one already?
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.
Thank you for iterating on this, In my tests, these changes did not cause any regressions, and make the current behavior better 👍
There are still some improvements that can be done, but they are a good fit for another follow-up PR.
I removed comment as my test environment for the case I referred was wrong I think this totally addresses #12310. |
* Fix converting caption shortcode with link * Parse HTML to DOM instead of using RegExp * Source anchor info only from first element
Fixes #13527 See original work in #12315 When pasting content which includes the `[caption]` shortcode we assume that the content is well-formed (that there is not only an `<img />` in there but also in the first position). In this patch we fix the problem by removing the old code, which removed the first `Element` node, and replaced it with code that removes the first `IMG` node _if one is found_. We're leaving other image nodes in place in case the caption contains image nodes and we're not requiring that the `IMG` be the first child of the caption shortcode in case people are wrapping the image in other valid HTML like this... ```html [caption]<a href="some.link"><img src="some.image"></a>[/caption] ``` See the new unit tests for a more complete specification of the intended behaviors. PR reviewed, debugged, and created by: -> LANNISTER MOB <- - @codebykat - @dmsnell - @gwwar - @kwight - @mmtr - @obenland - @rodrigoi - @vindl
* Fix: Pasting captions without an image fails Fixes #13527 See original work in #12315 When pasting content which includes the `[caption]` shortcode we assume that the content is well-formed (that there is not only an `<img />` in there but also in the first position). In this patch we fix the problem by removing the old code, which removed the first `Element` node, and replaced it with code that removes the first `IMG` node _if one is found_. We're leaving other image nodes in place in case the caption contains image nodes and we're not requiring that the `IMG` be the first child of the caption shortcode in case people are wrapping the image in other valid HTML like this... ```html [caption]<a href="some.link"><img src="some.image"></a>[/caption] ``` See the new unit tests for a more complete specification of the intended behaviors. PR reviewed, debugged, and created by: -> LANNISTER MOB <- - @codebykat - @dmsnell - @gwwar - @kwight - @mmtr - @obenland - @rodrigoi - @vindl * Update stripFirstImage behavior to also remove matching topmost parent node
* Fix: Pasting captions without an image fails Fixes #13527 See original work in #12315 When pasting content which includes the `[caption]` shortcode we assume that the content is well-formed (that there is not only an `<img />` in there but also in the first position). In this patch we fix the problem by removing the old code, which removed the first `Element` node, and replaced it with code that removes the first `IMG` node _if one is found_. We're leaving other image nodes in place in case the caption contains image nodes and we're not requiring that the `IMG` be the first child of the caption shortcode in case people are wrapping the image in other valid HTML like this... ```html [caption]<a href="some.link"><img src="some.image"></a>[/caption] ``` See the new unit tests for a more complete specification of the intended behaviors. PR reviewed, debugged, and created by: -> LANNISTER MOB <- - @codebykat - @dmsnell - @gwwar - @kwight - @mmtr - @obenland - @rodrigoi - @vindl * Update stripFirstImage behavior to also remove matching topmost parent node
* Fix: Pasting captions without an image fails Fixes #13527 See original work in #12315 When pasting content which includes the `[caption]` shortcode we assume that the content is well-formed (that there is not only an `<img />` in there but also in the first position). In this patch we fix the problem by removing the old code, which removed the first `Element` node, and replaced it with code that removes the first `IMG` node _if one is found_. We're leaving other image nodes in place in case the caption contains image nodes and we're not requiring that the `IMG` be the first child of the caption shortcode in case people are wrapping the image in other valid HTML like this... ```html [caption]<a href="some.link"><img src="some.image"></a>[/caption] ``` See the new unit tests for a more complete specification of the intended behaviors. PR reviewed, debugged, and created by: -> LANNISTER MOB <- - @codebykat - @dmsnell - @gwwar - @kwight - @mmtr - @obenland - @rodrigoi - @vindl * Update stripFirstImage behavior to also remove matching topmost parent node
Description
Avoids a duplicate image when converting from a classic block.
Fixes #12310.
Testing Instructions
- In master we see:
In the branch we see:
How has this been tested?
See #12310. E2e tests have been added.
Screenshots
Types of changes
Bug fix
Checklist: