{{ message }}
Repository navigation
fix(muya): give each repeated footnote reference its own id and backref - #5492
Merged
Merged
Conversation
Every reference to the same note carried `id="fnref-N"`, so a note cited
more than once produced duplicate ids — invalid HTML, and the note's single
backlink arrow could only ever reach the first of them.
Number the occurrences: the first keeps `fnref-N`, later ones take a
`-k` suffix, and the note gets one arrow per reference (bare for the first,
numbered after that). This is the shape GFM emits; pandoc instead duplicates
the note itself, which loses the "one note, cited twice" relationship.
The editor's inline renderer still emits `id="noteref-{identifier}"` per
reference. Left alone here: the fix needs document-wide occurrence numbering
that the per-block inline renderer doesn't have, and in a contenteditable
DOM the current behaviour (backlink lands on the first reference) is benign.
Closes #5488
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Jocs
force-pushed
the
fix/footnote-duplicate-ref-id-5488
branch
from
September 21, 2026 23:30
30c2e2b to
bbd4207
Compare
csells
added a commit
to csells/MarkText
that referenced
this pull request
Sep 25, 2026
Upstream's export numbers every reference to a note with its own id (fnref-N, fnref-N-2, ...) and one backref per reference, and leaves a reference inside a note body literal (marktext#5492). The document-model export gave repeated references one shared id and a single backref, and resolved references inside note bodies; render them as upstream does through Muya's shared footnote helpers.
csells
added a commit
to csells/MarkText
that referenced
this pull request
Sep 25, 2026
Upstream's export numbers every reference to a note with its own id (fnref-N, fnref-N-2, ...) and one backref per reference, and leaves a reference inside a note body literal (marktext#5492). The document-model export gave repeated references one shared id and a single backref, and resolved references inside note bodies; render them as upstream does through Muya's shared footnote helpers.
csells
added a commit
to csells/MarkText
that referenced
this pull request
Oct 13, 2026
Upstream's export numbers every reference to a note with its own id (fnref-N, fnref-N-2, ...) and one backref per reference, and leaves a reference inside a note body literal (marktext#5492). The document-model export gave repeated references one shared id and a single backref, and resolved references inside note bodies; render them as upstream does through Muya's shared footnote helpers.
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.

Closes #5488
Problem
Every reference to a given note was rendered with the same
id:idmust be unique in a document, and the consequence is not only formal: the note carried a single↩pointing atfnref-1, so the second and later references were unreachable — the arrow always landed on the first one.Fix
Number the occurrences. The first reference keeps
fnref-N; later ones take a-ksuffix, and the note gets one arrow per reference — bare for the first, numbered after that, so they can be told apart:This is the shape GFM emits. pandoc takes the other route and duplicates the note itself (two entries numbered 1 and 2), which loses the "one note, cited twice" relationship — muya's reuse is the better behaviour, so only the id allocation and the backref set change here.
A note referenced once is untouched: same single
fnref-N, same bare↩.Out of scope
The editor's inline renderer still puts
id="noteref-{identifier}"on every reference (packages/muya/src/inlineRenderer/renderer/footnoteIdentifier.ts), so the same duplication exists in the contenteditable DOM. Fixing that needs document-wide occurrence numbering, which the per-block inline renderer has no access to, and the current behaviour there is benign —Footnote's backlink callsgetElementById, which lands on the first reference. Noted in #5488 rather than bundled here.Tests
New in
packages/muya/src/state/__tests__/footnoteHtml.spec.ts:fnref-1,fnref-1-2,fnref-1-3, and three backref arrows labelled↩,↩2,↩3, each pointing at its own reference↩The first fails on
develop; the second passes either way and pins the common case against the change.Verification
muya unit suite 1987 ✅, CommonMark/GFM conformance 1347 ✅, eslint + tsc ✅, desktop unit suite 861 ✅, desktop build ✅.