fix: Remove {:.no_toc} paragraphs from HTML output#112
Merged
Conversation
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 <noreply@anthropic.com>
There was a problem hiding this comment.
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()togenerateTOCFromDoc()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
UseJekyllHTMLdefault value ingetTOCOptions()fromfalsetotrueto match Jekyll's expected output format - Added comprehensive regression test
TestNoTocParagraphRemovalthat 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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, butgenerateTOC()was parsing HTML again into a separate DOM tree. WhenhasNoTocSibling()removed the{:.no_toc}paragraph during TOC generation, the removal only affected the second DOM tree, not the one rendered to output.Fix
generateTOC()togenerateTOCFromDoc()which accepts an already-parsed*html.Nodeinstead of[]byteprocessTOC()to pass its DOM tree directly, so modifications made byextractHeadings()(viahasNoTocSibling()) are preserved in the final outputUseJekyllHTMLdefault ingetTOCOptions()fromfalsetotrueto match Jekyll's<ul id="markdown-toc">output formatTest plan
TestNoTocParagraphRemovalusing exact repro from issue comments🤖 Generated with Claude Code