-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Table Of Contents: Include headings exclusively within the core/post-content
block
#69366
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
Conversation
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 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. |
13f9d73
to
4aa0eb4
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.
Thank you, @yogeshbhutkar!
The fix works as expected ✅
@yogeshbhutkar, rebasing on top of the lastest trunk should resolve e2e test failures. |
4aa0eb4
to
ec6801e
Compare
…-content` block (WordPress#69366) Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: ryelle <ryelle@git.wordpress.org>
What?
Closes #69359
This PR updates the logic to ensure the
Table of Contents
block only considersHeading
elements within thecore/post-content
block. Previously, it included all headings on the page, including those in theHeader
andFooter
, which could lead to unintended results.Why?
Including
Heading
elements from outside thecore/post-content
block—such as those in theHeader
andFooter
—in theTable of Contents
block is not ideal, as it should strictly focus on the main content. The block should serve its intended purpose of summarizing the structure of the post by tabulating only theHeading
tags used within the post content.How?
The previous implementation used
getClientIdsWithDescendants
to get the client IDs of all the blocks in the editor. When theShow Template
mode is toggled (template-locked
editing mode ), this selector literally returns all the blocks within the editor. That includes theHeader
,Footer
, and the blocks within theTemplate
. This behavior causes the bug mentioned above.The current PR updates the usage to use
getClientIdsOfDescendants
to exclusively get the nested blocks within thepost-content
using itsClient ID
. If theClient ID
becomes undefined or an empty string for some reason ( e.g. when editing mode is set to post-only ), in such a scenario, it gracefully falls back to return thetop-level
blocks.Testing Instructions
Heading
elements to theHeader
,Footer
, or within theTemplate
.Heading
elements inside the post content.Header
,Footer
, orTemplate
.Screenshots
Testing edge cases
