Skip to content

Add opt-in collapsible option to TableOfContentsExtension - #259

Merged
dereuromark merged 1 commit into
masterfrom
feature/collapsible-toc
Jul 8, 2026
Merged

Add opt-in collapsible option to TableOfContentsExtension#259
dereuromark merged 1 commit into
masterfrom
feature/collapsible-toc

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

What

Adds an opt-in collapsible option to TableOfContentsExtension that wraps the generated table of contents in an HTML5 <details>/<summary> disclosure, so a long contents list can start collapsed and expand on click.

Mirrors markup-carve/carve-php#297 (the carve-php line), keeping the two library families consistent.

Behavior

  • Default off. With collapsible unset the output is the unchanged <nav class="toc">, so existing consumers are unaffected.
  • When on, the heading list sits directly inside the disclosure (no <nav>):
<details class="toc">
<summary>Table of Contents</summary>
<ul> ... </ul>
</details>
  • summary (default Table of Contents) sets the label and is HTML-escaped.
  • open renders it expanded; closed by default.

Motivation

The wp-djot plugin currently produces a collapsible TOC via a plugin-level preg_replace hack that rewrites the emitted <nav class="toc"> into a <details>. This option lets the plugin drop that hack and use the library directly.

Tests

4 new cases: collapsible closed/open, custom + escaped summary, and the unchanged non-collapsible path. TOC suite green; phpstan + phpcs clean on the touched files.

Wrap the generated table of contents in a <details>/<summary>
disclosure when collapsible is true, so a long contents list can
start collapsed and expand on click. Off by default: the output stays
the unchanged <nav class="toc">.

When enabled the heading list sits directly inside the disclosure:

    <details class="toc">
    <summary>Table of Contents</summary>
    <ul> ... </ul>
    </details>

The summary parameter sets the label (default "Table of Contents")
and open renders it expanded.
@dereuromark dereuromark added the enhancement New feature or request label Jul 8, 2026
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.37%. Comparing base (df3ce69) to head (70dcd36).

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #259   +/-   ##
=========================================
  Coverage     92.37%   92.37%           
- Complexity     3633     3635    +2     
=========================================
  Files           109      109           
  Lines         10277    10283    +6     
=========================================
+ Hits           9493     9499    +6     
  Misses          784      784           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dereuromark
dereuromark merged commit 7c660d4 into master Jul 8, 2026
6 checks passed
@dereuromark
dereuromark deleted the feature/collapsible-toc branch July 8, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant