Skip to content

Fix TabsExtension breaking TableOfContentsExtension#140

Merged
dereuromark merged 1 commit intomasterfrom
fix/tabs-extension-toc-compatibility
Mar 28, 2026
Merged

Fix TabsExtension breaking TableOfContentsExtension#140
dereuromark merged 1 commit intomasterfrom
fix/tabs-extension-toc-compatibility

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Summary

Fixes #139

The TabsExtension was calling $converter->render() for nested tab content, which triggered clear() on all extensions including TableOfContentsExtension. This wiped out all headings collected before the tabs div, causing TOC to only show headings that appeared after the tabs.

Root Cause

In DjotConverter::render():

public function render(Document $document): string
{
    foreach ($this->extensions as $extension) {
        if (method_exists($extension, 'clear')) {
            $extension->clear();
        }
    }
    return $this->renderer->render($document);
}

When TabsExtension called $converter->render($tempDoc) to render tab panel content, it triggered this clear() which reset the TOC's $this->toc = [].

Fix

Use the renderer directly via $converter->getRenderer()->render() instead of $converter->render() to avoid triggering the clear() call on extensions.

Changes

  • Modified TabsExtension to use renderer directly for nested content
  • Added 3 regression tests for TOC compatibility:
    • testCompatibilityWithTableOfContents - verifies all headings before/after tabs are captured
    • testTocCapturesHeadingsInsideTabs - verifies H2s around tabs are captured
    • testTocWithTabsUsingLabelAttribute - verifies headings inside tabs with label attribute are captured

The TabsExtension was calling $converter->render() for nested tab
content, which triggered clear() on all extensions including TOC.
This wiped out all headings collected before the tabs div.

Now uses the renderer directly via $converter->getRenderer() to avoid
the clear() call, preserving extension state during nested rendering.

Fixes #139
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.21%. Comparing base (46d5866) to head (d42caee).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #140   +/-   ##
=========================================
  Coverage     94.21%   94.21%           
  Complexity     2570     2570           
=========================================
  Files            88       88           
  Lines          6846     6847    +1     
=========================================
+ Hits           6450     6451    +1     
  Misses          396      396           

☔ View full report in Codecov by Sentry.
📢 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 5b6b08f into master Mar 28, 2026
6 checks passed
@dereuromark dereuromark deleted the fix/tabs-extension-toc-compatibility branch March 28, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TabsExtension breaks TableOfContentsExtension heading collection

1 participant