-
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
Run wp.oldEditor.removep()
when transforming shortcodes
#8077
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.
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. |
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.
🎉
@@ -1,6 +1,7 @@ | |||
/** | |||
* WordPress dependencies | |||
*/ | |||
import { removep, autop } from '@wordpress/autop'; |
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.
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.
@@ -46,7 +47,7 @@ export const settings = { | |||
text: { | |||
type: 'string', | |||
shortcode: ( attrs, { content } ) => { | |||
return content; | |||
return removep( autop( content ) ); |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: