Skip to content

Conversation

@osteele
Copy link
Owner

@osteele osteele commented Nov 30, 2025

Summary

Fixes #100

The {:.no_toc} kramdown IAL marker was correctly excluding headings from the TOC, but the marker paragraph itself remained in the rendered HTML output.

Root Cause

processTOC() was parsing HTML into a DOM tree for marker replacement, but generateTOC() was parsing HTML again into a separate DOM tree. When hasNoTocSibling() removed the {:.no_toc} paragraph during TOC generation, the removal only affected the second DOM tree, not the one rendered to output.

Fix

  • Renamed generateTOC() to generateTOCFromDoc() which accepts an already-parsed *html.Node instead of []byte
  • This allows processTOC() to pass its DOM tree directly, so modifications made by extractHeadings() (via hasNoTocSibling()) are preserved in the final output
  • Also fixed UseJekyllHTML default in getTOCOptions() from false to true to match Jekyll's <ul id="markdown-toc"> output format

Test plan

  • Added regression test TestNoTocParagraphRemoval using exact repro from issue comments
  • All existing TOC tests pass
  • Full test suite passes
  • Linting passes

🤖 Generated with Claude Code

Fixes #100

The {:.no_toc} kramdown IAL marker was being used to exclude headings from
the TOC, but the marker paragraph itself remained in the rendered HTML output.

Root cause: processTOC() was parsing HTML into a DOM for marker replacement,
but generateTOC() was parsing HTML again into a separate DOM tree. When
hasNoTocSibling() removed the {:.no_toc} paragraph during TOC generation,
the removal only affected the second DOM tree, not the one rendered to output.

Fix: Renamed generateTOC() to generateTOCFromDoc() which accepts an
already-parsed *html.Node instead of []byte. This allows processTOC() to
pass its DOM tree directly, so modifications made by extractHeadings()
(via hasNoTocSibling()) are preserved in the final output.

Also fixed UseJekyllHTML default in getTOCOptions() from false to true to
match Jekyll's <ul id="markdown-toc"> output format.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #100 where {:.no_toc} kramdown IAL marker paragraphs were incorrectly appearing in the rendered HTML output. The root cause was that TOC generation was parsing HTML into a separate DOM tree, causing the removal of {:.no_toc} paragraphs to be lost.

Key changes:

  • Refactored generateTOC() to generateTOCFromDoc() to accept an already-parsed DOM tree, ensuring that mutations made during heading extraction (specifically the removal of {:.no_toc} paragraphs) are preserved in the final output
  • Fixed UseJekyllHTML default value in getTOCOptions() from false to true to match Jekyll's expected output format
  • Added comprehensive regression test TestNoTocParagraphRemoval that verifies the fix

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
renderers/renderers.go Corrected default UseJekyllHTML value from false to true to align with Jekyll-compatible output
renderers/markdown_toc.go Refactored generateTOC() to generateTOCFromDoc() to accept pre-parsed DOM tree, ensuring {:.no_toc} paragraph removals are preserved in final output
renderers/markdown_toc_test.go Added comprehensive regression test verifying {:.no_toc} paragraphs are removed from output while headings are excluded from TOC but remain in document body

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@osteele osteele merged commit f7b210e into main Nov 30, 2025
10 checks passed
@osteele osteele deleted the fix-no-toc-removal branch November 30, 2025 11:20
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.

toc does not respect {:.no_toc}

2 participants