Skip to content

Give Word footnotes the treatment comments got — a note's reference is a link to nowhere today, and its text an unlabeled list at the end #191

Closed

Description

@bencode

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> (mammoth document-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 to unlinkComments (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, so N matches).

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 check

Refs

Activity

  1. added
    enhancement
    source:scheduled
    on Oct 23, 2026
  2. bencode commented on Oct 23, 2026

    @bencode
    OwnerAuthor

    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:scheduled proposals. Audited against main@fc25139.

    Evidence audit: every citation confirmed; the mammoth internals verified at source level.

    • ✅ mammoth lib/document-to-html.js:399-408 — noteReference emits <sup><a href="#footnote-N" id="footnote-ref-N">[N]</a></sup>; the id prefixes confirmed via referentHtmlId/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 — unlinkComments with the "links that go nowhere" reasoning verbatim at :63; :108-111 — the DOM pass (parseFromString → flattenTableCells → promoteHeaderRow → unlinkComments) is exactly where the rewrite belongs; no footnote string exists in the converter (anchor red).
    • ✅ markdown-reader/index.tsx:182-186 — navigateToHeading resolves headingElements.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.
    • ✅ Not a duplicate: Let readers follow the links in their own notes — [[wiki-links]] render as plain text while the assistant walks the graph #95 (closed) was the notes' own wiki-links; Let a reader follow a PDF's own links — a 'see Figure 3', citation or table-of-contents click does nothing today #189 is PDF internal links — this is the Word converter face; no other footnote issue exists.

    Sensor: lint ✓; verify ✗ on main → stays open. The anchor is deliverable-shaped — any rewrite must match Mammoth's footnote hrefs.

    Sharpening, two lines from the source: (1) the same noteReference/note machinery also carries endnotes, whose ids come out endnote-N/endnote-ref-N (referentHtmlId is noteType-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 carrying footnote/endnote ids, not merely by being "the last <ol>".

    Verdict: valid, keep open. No commit implements or invalidates it.

  3. bencode commented on Oct 24, 2026

    @bencode
    OwnerAuthor

    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 at main@fc25139.

    Drift check: 15 commits since the last review (tab dragging, conversation numbers, composer refactors, background conversations) — none touch formats/ or markdown-reader/; no dependency change, so the mammoth 1.12.3 document-to-html.js internals verification stands.

    Evidence audit: re-confirmed at HEAD —

    • ui-packages/web/src/formats/docx.ts:63-74 — unlinkComments with the "links that go nowhere" reasoning ✓; :108-111 — the DOM pass (parseFromString → flattenTableCells → promoteHeaderRow → unlinkComments) ✓; no footnote string anywhere in the converter — anchor red ✓
    • markdown-math.ts:2-4 — remarkGfm in 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 — no footnote in docx.ts, so not implemented.

    Sharpening still open (carried from the prior review, unchanged): match both footnote-N and endnote-N id prefixes (Mammoth prefixes ids with noteType), 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsource:scheduled

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions