Description
This issue sets up discussion started during a Core Editor chat for the functionality of a Table of Contents (TOC) Block. Currently, there are several PRs/Issues that provide possible solutions.
Add Table of Contents block (dynamic rendering + hooks version) PR #21234
"Table of Contents" Block PR #11047
#15426 (Closed) PR #15426
From a technical point, when working with a TOC block, how are items that aren't in blocks like headings and next page tags counted, and how is it determined if those items precede the current block? Counting Heading blocks is relatively easy, but counting all headings in the HTML is more difficult, and counting all headings in the HTML preceding the current block seems impossible in some situations. This challenge is compounded when considering if the headings are in a dynamic block.
Resolving these questions impacts:
- Completion of the TOC block
- Addressing edge-cases with the heading level checker in PR Heading block: add heading level checker #22650
- Application for the existing content structure tool in the top toolbar.
- Some Full Site Editing (FSE) blocks like site-title or post-title if the HTML is not set as an h1
Specific challenges that need feedback are:
- Should the TOC block only support Heading Blocks?
- How is support added for 3rd-party heading blocks?
- Should there be some kind of generic "headings" API for blocks to hook into that is abstracted away from HTML?
- What is involved in supporting third-party heading blocks?
Possible solutions include:
- Something like allowing a block to declare one of its attributes as contributing to the outline of a document and abstracting away outline/table of contents in a getOutline rather than just getting core/heading. @mtias
- Potentially adding a dedicated block API for third-party blocks. @youknowriad
@ZebulanStanphill @mtias @youknowriad @MichaelArestad contributed to the original conversation. Additional feedback here is welcome.