Skip to content

fix(markdown): clean heading links — wrap text in anchor instead of # marker#70

Merged
x3ek merged 2 commits intomainfrom
fix/68-clean-heading-links
Mar 12, 2026
Merged

fix(markdown): clean heading links — wrap text in anchor instead of # marker#70
x3ek merged 2 commits intomainfrom
fix/68-clean-heading-links

Conversation

@x3ek
Copy link
Contributor

@x3ek x3ek commented Mar 12, 2026

Summary

  • Replaces TocExtension(permalink="#") with permalink=False + a custom HeadingAnchorTreeprocessor that wraps heading text in <a class="heading-anchor" href="#id">
  • The # marker is gone from all themes; heading text itself is now the link target
  • Updates all three bundled themes to style .heading-anchor instead of .headerlink
  • Renames test_heading_anchor_uses_hashtest_heading_text_is_anchor_link with updated assertions

Before: <h2 id="hello-world">Hello World<a class="headerlink" href="#hello-world">#</a></h2>
After: <h2 id="hello-world"><a href="#hello-world" class="heading-anchor">Hello World</a></h2>

Closes #68

…# marker

Replaces TocExtension permalink='#' with a custom HeadingAnchorTreeprocessor that wraps heading text in <a class="heading-anchor" href="#id">. Updates all three bundled themes to style .heading-anchor instead of .headerlink. Closes #68.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@x3ek x3ek added this to the SquishMark 1.0 milestone Mar 12, 2026
@x3ek x3ek requested a review from Copilot March 12, 2026 16:13
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

Updates SquishMark’s Markdown rendering so headings link cleanly to their own anchors by wrapping the heading text in an <a class="heading-anchor" href="#...">...</a> instead of rendering a visible # permalink marker, and aligns bundled themes/tests with the new markup.

Changes:

  • Adds a custom Python-Markdown treeprocessor/extension to wrap heading contents in a self-referencing anchor while disabling TocExtension permalinks.
  • Updates bundled themes to style .heading-anchor (replacing .headerlink styling).
  • Updates/renames the markdown heading permalink test to assert the new behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/squishmark/services/markdown.py Adds HeadingAnchorTreeprocessor + extension and switches TocExtension(permalink="#") to permalink=False.
tests/test_markdown.py Renames and updates the heading anchor test for the new markup.
themes/default/static/style.css Adds .heading-anchor styling for default theme.
themes/blue-tech/static/style.css Replaces .headerlink styles with .heading-anchor styles.
themes/terminal/static/css/style.css Replaces .headerlink styles with .heading-anchor styles.

You can also share your feedback on Copilot code review. Take the survey.

…test coverage

- Skip headings that already contain <a> descendants to avoid invalid nested anchors
- Move .heading-anchor rules after general link rules in all three themes so the cascade works correctly
- Add explicit assertion that heading text is inside the anchor element
- Add test for linked headings not getting wrapped

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@x3ek
Copy link
Contributor Author

x3ek commented Mar 12, 2026

Playwright testing — all three themes verified

Tested locally against all three bundled themes with a fresh browser session (no cache).

HTML structure

<h2 id="stage-1-denial"><a class="heading-anchor" href="#stage-1-denial">Stage 1: Denial</a></h2>

No # marker, no nested anchors, heading text is the link.

Results

Theme Heading color (computed) text-decoration Anchor click → hash
default rgb(196, 101, 42) (orange, inherited) none
blue-tech rgb(255, 255, 255) (white, inherited) none
terminal green (inherited) none

CSS cascade fix confirmed working — anchors inherit the heading color rather than the general link color in all themes.

— Claude

@x3ek x3ek merged commit a098986 into main Mar 12, 2026
5 checks passed
@x3ek x3ek deleted the fix/68-clean-heading-links branch March 12, 2026 17:12
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.

Replace heading # anchor markers with clean heading links

2 participants