-
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
Parser / Site Editor: Ensure autop is not run when freeform block is set to core/html #52716
Parser / Site Editor: Ensure autop is not run when freeform block is set to core/html #52716
Conversation
Size Change: +16 B (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
Flaky tests detected in fe4641728cc4dbd5f93d30e31d442e9fb8f30676. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5583963619
|
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 for working on this!
The approach looks good to me. However, after a quick grep, I think we are forgetting this other instance where the inverse — removep
— is called during serialisation:
gutenberg/packages/blocks/src/api/serializer.js
Lines 391 to 396 in 276d336
if ( | |
blocks.length === 1 && | |
blocks[ 0 ].name === getFreeformContentHandlerName() | |
) { | |
content = removep( content ); | |
} |
I believe that condition should be amended in the same way:
// For compatibility, treat a post consisting of a
// single freeform block as legacy content and apply
// pre-block-editor removep'd content formatting.
if (
blocks.length === 1 &&
blocks[ 0 ].name === getFreeformContentHandlerName()
+ blocks[ 0 ].name !== 'core/html'
) {
content = removep( content );
}
@@ -101,6 +101,7 @@ export function normalizeRawBlock( rawBlock, options ) { | |||
// meaning there are no negative consequences to repeated autop calls. | |||
if ( | |||
rawBlockName === fallbackBlockName && | |||
rawBlockName !== 'core/html' && |
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.
This makes sense. I dare say this could even be rawBlockName === 'core/freeform'
— to me, autop and freeform go together as descendants of WP's original simplified approach to post_content, where any block of text would be interpreted as a P tag. In other words, I can't think of a scenario with any block type other than freeform that would want autop.
Thanks for the review and feedback @mcsf! Doing a check for I've updated this PR now. I also needed to update a fair few tests that referred to |
Thanks for working on this @andrewserong If it's all good with @mcsf, then it LGTM!
|
328902e
to
4c01a3b
Compare
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, thank you @andrewserong !
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.
If it's all good with @mcsf, then it LGTM!
Yup! :)
Thanks folks! 🙇 |
…set to core/html (#52716) * Parse / Site Editor: Ensure autop is not run when freeform block is set to core/html * Switch to equals freeform instead of not equals core/html * Rename core/test-freeform to core/freeform in tests
I just cherry-picked this PR to the update/packages-RC2 branch to get it included in the next release: 790b744 |
* Filter out patterns that are not allowed in the inserter (#52675) * Remove autofocus and improve placeholder text consistency. (#52634) * Do not navigate to the styles pages unless you're in a random listing page (#52728) * Patterns: Don't override the rootClientID in create menu - only set if undefined (#52713) * Footnotes: store in revisions (#52686) * Fix: Block toolbar obscuring document tools when Top Toolbar is enabled (#52722) * Update toolbar width * Site editor needs specific width * fixes top toolbar width for post editor when not in fullscreen * remove the body rule --------- Co-authored-by: Andrei Draganescu <[email protected]> * Site Editor: Fix site link accessibility issues (#52744) * Add id to pattern inserted notice to stop multiple notices stacking (#52746) * Global Styles: Don't use named arguments for 'sprintf' (#52782) * Footnotes: Use static closures when not using '' (#52781) * removes check for active preview device type to enable the fixed toolbar preference (#52770) * Parser / Site Editor: Ensure autop is not run when freeform block is set to core/html (#52716) * Parse / Site Editor: Ensure autop is not run when freeform block is set to core/html * Switch to equals freeform instead of not equals core/html * Rename core/test-freeform to core/freeform in tests * Adding @SInCE annotation for relevant 6.3 changes. (#52820) * Navigation: Load the raw property on the navigation fallback (#52758) * Navigation: Load the raw property on the navigation fallback * Update lib/compat/wordpress-6.3/navigation-fallback.php Co-authored-by: Dave Smith <[email protected]> * Update lib/compat/wordpress-6.3/navigation-fallback.php Co-authored-by: Dave Smith <[email protected]> * Add a test for these properties * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * add more comments * add necessary method * Fix php coding standards error --------- Co-authored-by: Dave Smith <[email protected]> Co-authored-by: Jerry Jones <[email protected]> * Allow styles to be changed dynamically through editor settings (#52767) * ResizableFrame: Fix styling in Firefox (#52700) * ResizableFrame: Fix styling in Firefox * Remove unused class * Patterns: Fix empty general template parts category (#52747) --------- Co-authored-by: Glen Davies <[email protected]> --------- Co-authored-by: Carolina Nymark <[email protected]> Co-authored-by: Andrea Fercia <[email protected]> Co-authored-by: Riad Benguella <[email protected]> Co-authored-by: Glen Davies <[email protected]> Co-authored-by: Ella <[email protected]> Co-authored-by: James Koster <[email protected]> Co-authored-by: Andrei Draganescu <[email protected]> Co-authored-by: George Mamadashvili <[email protected]> Co-authored-by: Andrei Draganescu <[email protected]> Co-authored-by: Andrew Serong <[email protected]> Co-authored-by: Ramon <[email protected]> Co-authored-by: Ben Dwyer <[email protected]> Co-authored-by: Dave Smith <[email protected]> Co-authored-by: Jerry Jones <[email protected]> Co-authored-by: Lena Morita <[email protected]> Co-authored-by: Kai Hao <[email protected]> Co-authored-by: Glen Davies <[email protected]>
What?
Possible fix for #49166
If the freeform block for the editor is set to
core/html
, skip runningautop
on raw parsed blocks. To achieve this, this PR now runsautop
only when the freeform block is set tocore/freeform
(the Classic block).This should hopefully resolve an issue where custom HTML added to a template would receive unexpected
<p>
and<br>
tags.Why?
Back in #48129, the site editor was updated to set
setFreeformFallbackBlockName
tocore/html
so that freeform content would be treated as an HTML block. However, innormalizeRawBlock
raw content matching the fallback block name gets run throughautop
to automatically addp
andbr
tags. From context, I believe this is to ensure that Classic blocks in post content correctly receive paragraph and break tags and such. In the site editor / when editing templates, I believe this is not required or expected, especially now that freeform content is treated as HTML blocks.How?
In the parser's
normalizeRawBlock
function, only applyautop
when the freeform block is set tocore/freeform
, so that editors that usecore/html
do not unexpectedly include automatically insertedp
andbr
tags.Update tests that relate to the freeform block behaviour so that they use the string
core/freeform
for the block name for consistency (and to catch the expected default behaviour).Testing Instructions
<p>
tags in your Custom HTML. With this PR applied, after saving and reloading the template, there should not be extra<p>
tags added to the Custom HTML.Example markup to use:
Screenshots or screencast