Repository navigation
Description
Problem
A Word document with footnotes or endnotes — the shape every academic draft, legal memo and report comes in — converts today into two broken halves:
- In the body, Mammoth emits
<sup><a href="#footnote-3" id="footnote-ref-3">[3]</a></sup>(mammothdocument-to-html.js:399-408). Turndown keeps it as a markdown link to#footnote-3, but the<li id="footnote-3">it points at loses its id on the way through, and the reader resolves anchors only for registered headings (ui-packages/web/src/features/reader/markdown-reader/index.tsx:182-186:find(element => element.id === id),?.— no match, no scroll). Clicking a note reference does nothing. - At the end, Mammoth appends the notes as a bare
<ol>(document-to-html.js:352-363), each item trailing a dead↑back-link (:409-419). It reaches the reader as an unlabeled numbered list after the last paragraph — indistinguishable from the document's own content — and nothing names it as the notes.
This exact shape was already solved once in the same file: comments arrive as the same anchors-and-end-list, and unlinkComments deliberately removes the back-links and turns references into (1) text, with the reasoning written at ui-packages/web/src/formats/docx.ts:63-65 — "links that go nowhere". Footnotes pass through that pass untouched (no footnote handling exists in the converter; #45's markers cover only equations, charts and objects, and this content is not lost — it is severed from its references).
Meanwhile the reader already supports real footnotes: [^1] renders as superscript references with a Notes section (remark-gfm in markdownPlugins, ui-packages/web/src/formats/markdown-math.ts:2-4), and the text pipeline already treats footnote marks as auxiliary (ui-packages/web/src/formats/markdown-text.ts:25-26,37-41). Only the Word path fails to produce them.
Proposal
- In the DOM pass of
convertDocxToMarkdown, next tounlinkComments(ui-packages/web/src/formats/docx.ts:108-111), rewrite Mammoth's note machinery into the footnote syntax the reader already renders: each body reference<a href="#footnote-N">[N]</a>becomes[^N], and the trailing<ol>of notes is replaced by[^N]: <text>definitions (the comment pass at :63-74 is the template; Mammoth numbers references in body order, soNmatches).
Goal
After this, a Word document's footnotes read like footnotes: superscript references in place that jump to their note and back, a labelled Notes section at the end — no dead links, no anonymous trailing list — the same fidelity #45 gave to equations and comments.
Verification
grep -q "footnote" ui-packages/web/src/formats/docx.ts
pnpm --filter @gamma-reader/web test --silent
pnpm checkRefs
- ui-packages/web/src/formats/docx.ts:63-74 —
unlinkComments, the deliberate treatment of the identical comment shape, and the model for this pass - ui-packages/web/src/formats/docx.ts:108-111 — the DOM pass where the handling belongs
- mammoth lib/document-to-html.js:399-419, :352-363 — the note references and the trailing
<ol>Mammoth emits - ui-packages/web/src/features/reader/markdown-reader/index.tsx:182-186 — anchors resolve only for headings, so today's note links are no-ops
- ui-packages/web/src/formats/markdown-math.ts:2-4 and markdown-text.ts:25-26 — the reader's own
[^N]footnote support this proposal reuses - Tell readers which Word content did not convert, instead of logging it to the browser console #45 — the completed unconverted-content work (equations, charts, objects); this is the converted-but-severed remainder
- Let a reader follow a PDF's own links — a 'see Figure 3', citation or table-of-contents click does nothing today #189 — the same "a link that does nothing" in PDFs; this is the Word face
- Show pending revisions in a Word document — today it opens as if every tracked change were accepted, the deleted text is gone, and nothing says review is unfinished #181 — other Word fidelity gaps already filed (tracked changes, merged cells)
Activity
bencode commentedon Oct 23, 2026
Independent review — posted by the scheduled issue-reviewer loop (a session separate from the one that files these issues), under the maintainer's standing instruction to evaluate, sharpen, or retire
source:scheduledproposals. Audited againstmain@fc25139.Evidence audit: every citation confirmed; the mammoth internals verified at source level.
lib/document-to-html.js:399-408—noteReferenceemits<sup><a href="#footnote-N" id="footnote-ref-N">[N]</a></sup>; the id prefixes confirmed viareferentHtmlId/referenceHtmlId(:219-225,noteType + "-" / "-ref-" + id);:408-417— each note is an<li id="footnote-N">trailing a dead↑back-link;:352-363— the document converter appends the notes as a bare<ol>after the content.docx.ts:63-74—unlinkCommentswith the "links that go nowhere" reasoning verbatim at:63;:108-111— the DOM pass (parseFromString→flattenTableCells→promoteHeaderRow→unlinkComments) is exactly where the rewrite belongs; nofootnotestring exists in the converter (anchor red).markdown-reader/index.tsx:182-186—navigateToHeadingresolvesheadingElements.current.find(element => element.id === id)with?.— anchors outside registered headings are no-ops, so today's note links do nothing.markdownPlugins = [remarkGfm, remarkMath, markSources](markdown-math.ts:94) — the reader's[^N]footnote support is real;markdown-text.ts:25-26,41-44— footnote refs/backrefs/label already read as auxiliary.Sensor:
lint✓;verify✗ on main → stays open. The anchor is deliverable-shaped — any rewrite must match Mammoth'sfootnotehrefs.Sharpening, two lines from the source: (1) the same
noteReference/notemachinery also carries endnotes, whose ids come outendnote-N/endnote-ref-N(referentHtmlIdisnoteType-prefixed) — match both prefixes or endnote documents stay severed. (2) Mammoth appends notes<ol>and comments<dl>in one concat (:359-363); the trailing notes list should be identified by its items carryingfootnote/endnoteids, not merely by being "the last<ol>".Verdict: valid, keep open. No commit implements or invalidates it.
bencode commentedon Oct 24, 2026
Independent re-review — posted by the scheduled issue-reviewer loop, independent of the session that authored this issue. Audited against
main@90b046f; last review stood atmain@fc25139.Drift check: 15 commits since the last review (tab dragging, conversation numbers, composer refactors, background conversations) — none touch
formats/ormarkdown-reader/; no dependency change, so the mammoth 1.12.3document-to-html.jsinternals verification stands.Evidence audit: re-confirmed at HEAD —
ui-packages/web/src/formats/docx.ts:63-74—unlinkCommentswith the "links that go nowhere" reasoning ✓;:108-111— the DOM pass (parseFromString→flattenTableCells→promoteHeaderRow→unlinkComments) ✓; nofootnotestring anywhere in the converter — anchor red ✓markdown-math.ts:2-4—remarkGfmin the plugin set ✓;markdown-text.ts:25-26,37-41— footnote marks read as auxiliary ([data-footnote-ref],[data-footnote-backref],#footnote-label) ✓;markdown-reader/index.tsx:182-186— heading-only anchor resolution ✓Duplicate check (open + closed titles): none. Closed #45 covers unconverted-content markers (equations, charts, objects), not converted-but-severed notes; #189 is the PDF face of the same dead-link problem, already cross-referenced.
Sensor:
lint✓;verify✗ on main — nofootnoteindocx.ts, so not implemented.Sharpening still open (carried from the prior review, unchanged): match both
footnote-Nandendnote-Nid prefixes (Mammoth prefixes ids withnoteType), and identify the trailing notes list by its items' ids rather than by being the last<ol>(the comments<dl>is appended in the same concat).Verdict: still valid, keep open.