Run wp.oldEditor.removep() when transforming shortcodes#8077
Conversation
aduth
left a comment
There was a problem hiding this comment.
Can we use removep and autop from the @wordpress/autop package instead of relying on the global? (Should also then add wp-autop as a script dependency of the wp-core-blocks handle)
Yep e81c6ab |
|
I've added an extra check When Gutenberg saves a freeform block, it doesn't wrap it in the comment delimiters. When there's a single freeform block in the post, there's no way to tell that the post has been touched by Gutenberg, so Gutenberg needs to clean up after itself. This should possible be a seperate PR, but let's make this one the "fix the two issues reported #3900" PR. |
@pento Could you clarify what you mean by this? Are we going down the path of landing this and also recreating unbalanced / broken paragraph tags on the inner content prior to rendering the shortcode? |
|
@gziolo I'm not sure what's remaining on this. Do you know? |
|
I've turned Includes unit tests and such. |
Multi-line shortcodes transformed to Shortcode Blocks end up with `<p>` in awkward places. Thanks to @pento's quick thinking, we can use some existing WordPress magic to solve the immediate problem without falling into the deeper rabbit hole.
|
Also, I rebased/force pushed this branch, to get the latest version of the server fixtures, which I didn't really need to do, because |
|
💯 I tested this locally and it works exactly as expected. |
|
@WordPress/gutenberg-core This is ready for a final review/merge per #3900 (comment) All issues are addressed. |
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { removep, autop } from '@wordpress/autop'; |
There was a problem hiding this comment.
core-blocks does not have a dependency defined for wp-autop, so its existence is purely incidental and this could be prone to future breakage.
| type: 'string', | ||
| shortcode: ( attrs, { content } ) => { | ||
| return content; | ||
| return removep( autop( content ) ); |
There was a problem hiding this comment.
It's not evident why we're doing this. An inline code comment would have been appropriate.
| return serialize( getBlocks( state ) ); | ||
| const blocks = getBlocks( state ); | ||
|
|
||
| if ( blocks.length === 1 && blocks[ 0 ].name === getUnknownTypeHandlerName() ) { |
There was a problem hiding this comment.
It's not evident why we're doing this. An inline code comment would have been appropriate.
| import { __ } from '@wordpress/i18n'; | ||
| import { moment } from '@wordpress/date'; | ||
| import deprecated from '@wordpress/deprecated'; | ||
| import { removep } from '@wordpress/autop'; |
There was a problem hiding this comment.
editor does not have a dependency defined for wp-autop, so its existence is purely incidental and this could be prone to future breakage.
| * Test that shortcode blocks get the same HTML as shortcodes in Classic content. | ||
| */ | ||
| function test_the_content() { | ||
| add_shortcode( 'someshortcode', array( $this, 'handle_shortcode' ) ); |
There was a problem hiding this comment.
I'm not as familiar with PHP testing, but should we be tearing down anything we create, i.e. a complementing remove_shortcode?
| */ | ||
|
|
||
| /** | ||
| * Performs wpautop() on the shortcode block content. |
There was a problem hiding this comment.
Could be improved to explain why we're autop-ing, not simply expressing that we are, which is already evident in the code itself.
Alternatively, it could be considered an implementation detail that the block's render applies autop, not necessarily appropriate for the callback function. In other words, this function should be documented along lines of "Renders the shortcode", and the implementation detail explained by an inline code comment.
|
None of my comments are blocking for Try Callout, but could be considered for further improvement. |
|
Also noting that the |
Description
Multi-line shortcodes transformed to Shortcode Blocks end up with
<p>in awkward places. Thanks to @pento's quick thinking, we can use some
existing WordPress magic to solve the immediate problem without falling
into the deeper rabbit hole.
Fixes #3900
How has this been tested?
Open the post in Gutenberg and click "Convert to Blocks"
You should see the shortcode converted into a Shortcode Block without paragraph tags:
The prior behavior looked like this:
Types of changes
Bug fix.
Checklist: