Load Content Late - Add IDs After Others Have Addd Theirs #81
+233
−132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #58, Resolves #79
Continues #75
This is a draft PR demonstrating loading late and adding SimpleTOC after content has been parsed.
Features of Running Late
Caveats of loading late:
simpletoc_skip_in_wrapper(defaultfalse). If this is enabled, it'll get all headlines, even in other blocks and shortcode output.This flowchart shows the logic.
Block and Original Content Output
This runs whenever the block is initially output to the frontend (content priority
10) or when it is server-side rendered.If the block is server-side rendered (in REST), then a sample TOC is generated from block content, but only the TOC is returned, not the content.
Content Prority 800 - Add IDs Late
This assumes a shortcode is present in the content, which we'll replace later. In this iteration of content parsing, we're adding IDs to any headlines that don't already have them and storing all headlines for later retrieval.
TOC Rendering
TOC rendering is after all other content has finished running, and returns a rendered TOC. If it's parsed on regular content, a shortcode will be present and replaced with the TOC HTML.
This render is also part of the block server-side rendering, which passes attributes and wrapper classes. If a TOC-only flag is set, then only the TOC HTML is returned, and not the full content. This is useful for server-side rendering.
Test Pattern
Here is the Test Pattern I used.