Skip to content

Conversation

Copy link

Copilot AI commented Nov 8, 2025

Summary

This PR adds support for customizing the href attribute prefix in footnote links via the env.footnoteHrefPrefix parameter. This addresses the feature request to make footnote hash support custom href (often prefix), similar to the pattern used in markdown-it-github-headings.

Changes Made

  • Understand the current implementation and how it generates footnote IDs and hrefs
  • Add support for custom href prefix through env.footnoteHrefPrefix
  • Update render functions to use the custom prefix
  • Add comprehensive tests for custom href prefix functionality
  • Ensure backward compatibility (default behavior unchanged)
  • Run lint, build and tests
  • Update README with documentation and examples
  • Run security checks
  • Remove package-lock.json per review feedback

Core Implementation

  • Added render_footnote_href_prefix() helper function that returns the custom prefix from env.footnoteHrefPrefix or defaults to #
  • Updated render_footnote_ref() to use the custom href prefix for footnote references
  • Updated render_footnote_anchor() to use the custom href prefix for back-references
  • Registered the new helper function in the renderer rules

Use Cases

This feature enables:

  • Linking footnotes to different pages (e.g., /docs/page#fn1)
  • Custom URL structures for footnotes (e.g., https://example.com/docs#fn1)
  • Combining with docId for both custom IDs and custom hrefs

Documentation

  • Added new "Custom href prefix" section in README.md
  • Included examples showing usage with and without docId

Tests

  • Added test fixtures for custom href prefix usage
  • Added test for combined docId and custom href prefix
  • All 20 tests pass (16 existing + 4 new)
  • 100% code coverage maintained

Backward Compatibility

  • ✅ Maintains full backward compatibility - defaults to # when not specified
  • ✅ Works seamlessly with existing env.docId feature
  • ✅ All existing tests continue to pass
Original prompt

Please make footnote hash support custom href (often prefix).
Reference Flet/markdown-it-github-headings#18


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 8, 2025 14:27
Co-authored-by: ChenPi11 <102936596+ChenPi11@users.noreply.github.com>
Co-authored-by: ChenPi11 <102936596+ChenPi11@users.noreply.github.com>
Copilot AI changed the title [WIP] Add footnote hash support for custom href prefix Add support for custom href prefix in footnotes Nov 8, 2025
Copilot AI requested a review from ChenPi11 November 8, 2025 14:36
Copilot finished work on behalf of ChenPi11 November 8, 2025 14:36
@ChenPi11 ChenPi11 marked this pull request as ready for review November 8, 2025 14:38
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove package-lock.json.

Copy link
Author

Choose a reason for hiding this comment

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

Removed in commit 9a7260c.

@ChenPi11
Copy link
Owner

ChenPi11 commented Nov 8, 2025

@copilot Please solve the requested changes: "Please remove package-lock.json."

Co-authored-by: ChenPi11 <102936596+ChenPi11@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 8, 2025

@copilot Please solve the requested changes: "Please remove package-lock.json."

Done. Removed package-lock.json in commit 9a7260c.

Copilot AI requested a review from ChenPi11 November 8, 2025 15:32
Copilot finished work on behalf of ChenPi11 November 8, 2025 15:32
@ChenPi11 ChenPi11 merged commit 35f95df into master Nov 8, 2025
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.

2 participants