Skip to content

fix(extension): render transitively referenced footnotes - #586

Open
fzlzjerry wants to merge 1 commit into
yuin:v2from
fzlzjerry:fix/v2-nested-footnotes
Open

fzlzjerry wants to merge 1 commit into
yuin:v2from
fzlzjerry:fix/v2-nested-footnotes

Conversation

@fzlzjerry

Copy link
Copy Markdown

Refs: #584

The v2 footnote renderer collected document references but skipped references inside footnote definitions. A nested reference could therefore point to a definition that was never rendered; physically nested definitions could also cause a panic.

This indexes definitions separately, then follows references reachable from the document. Each newly referenced definition is queued once, so cycles terminate and unused definitions stay hidden. Leaf definitions are not rescanned, and backlinks retain their existing reference-index order.

Parser numbering and the separate v1 ordering question in #410 are unchanged.

Validation

  • Eleven regression/control cases cover chains, shared children, self-reference, cycles, nested definitions, prefixes, counts, and hidden unused notes. Nine fail on the original code; all pass with the fix.
  • make test passes with Go 1.25.14, 1.26.8 and 1.27.1, including README examples.
  • Full go test -race ./... passes.
  • make lint passes with both root and _benchmark/go modules in a local workspace; no tracked module files change.
  • 1,000 additional fixed-seed graph cases pass; the baseline fails 752.
  • make bench ran before/after. Added BenchmarkFootnoteRender makes the changed extension path reproducible; the default CommonMark benchmark does not link this extension.

Ten balanced-order samples of the new 50-note benchmark show the following allocation costs:

Case Before allocs/op After allocs/op
flat 662 664
unused 555 507

The flat case pays a small queue/stack allocation cost. Timings vary across runs, so this is not a general speedup claim.

Copilot AI lite review requested due to automatic review settings September 10, 2026 07:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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