Skip to content

Let a Word document's internal links land — its table of contents and cross-references survive conversion as #anchors, but the bookmarks they point at are dropped, so every entry is dead on click #280

Open

Description

@bencode

Problem

A Word report opens with its table of contents on the first screen, and every entry in it is dead. Mammoth converts both halves of Word's internal navigation: w:bookmarkStart becomes an empty <a id="…"> at the target (mammoth.browser.js:466-469, installed dependency) and an internal hyperlink becomes <a href="#…">. But the Markdown step throws the target half away: Turndown drops empty anchors, and ui-packages/web/src/formats/docx.ts:167-188 adds rules for notes and table cells but none for bookmarks. Verified with the exact configuration convertDocxToMarkdown uses: <h2><a id="_Toc123"></a>Results</h2> converts to ## Results — id gone — while See <a href="#_Toc123">Section 5</a> survives as [Section 5](#_Toc123). The reader cannot mend it: headings get positional ids markdown-heading-N (ui-packages/web/src/features/reader/markdown-reader/heading-model.ts:38-39, applied at markdown-reader/index.tsx:158-167), and a #-href renders as a plain anchor (file-link.tsx:18-23, components/markdown.tsx:58-79) whose hash finds no element. So the TOC, "see Section 5" cross-references and figure references — the navigation a long report carries in its own text — all do nothing when clicked, in a reader that already jumps to headings fine from its outline (markdown-reader/index.tsx:182-190). PDFs got their internal links in #189; Word's are still born dead.

Proposal

  • In convertDocxToMarkdown's HTML post-processing (docx.ts:160-165, alongside the existing table and comment passes), keep each bookmark target: carry the empty anchor's id onto the heading or paragraph it stands in, so the id survives Turndown in an element the reader anchors.
  • Make the reader follow a #-href that names an id in the same document: scroll the reading pane to that element, as the outline's scrollIntoView already does (markdown-reader/index.tsx:182-190).
  • A bookmark whose target is gone (deleted section) renders as the plain text it already falls back to — no broken link left pointing nowhere silently.

Goal

After this, a converted Word document navigates like the document its author wrote: clicking a table-of-contents entry or a cross-reference scrolls to its section, the same jump the outline performs, and no internal link in a Word file is dead on arrival.

Verification

grep -q "bookmark" 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 28, 2026
  2. bencode commented on Oct 29, 2026

    @bencode
    OwnerAuthor

    Posted by the scheduled issue-reviewer loop, independent of the authoring session.

    Audit at d05b6b6 (2026-10-29): valid — evidence intact (one drifted anchor, corrected below), not implemented on main. No duplicates (#177 is bookmark-less PDF navigation, unrelated).

    Evidence checks:

    • Reproduced the crux with the repo's own Turndown config: <h2><a id="_Toc123"></a>Results</h2> → ## Results (id gone), while See <a href="#_Toc123">Section 5</a> → [Section 5](#_Toc123) survives. Exactly as claimed.
    • docx.ts:160-165,167-188 — the post-processing passes and Turndown rules (notes, table cells) confirmed; none touch bookmarks.
    • mammoth.browser.js:466-469 — bookmarkStart → <a id="…"> confirmed.
    • file-link.tsx:18-23, components/markdown.tsx:58-79 — a #-href renders as a plain <a href="#…"> with no in-document click handling, so the hash finds nothing. Confirmed.
    • index.tsx:182-190 — the outline's navigateToHeading/scrollIntoView the proposal reuses. Confirmed.
    • Anchor drift: heading-model.ts:38-39 is past end-of-file (35 lines); the positional id markdown-heading-${index + 1} lives at heading-model.ts:30. Claim itself is correct.

    Sensor: lint ✓; verify fails as expected (no bookmark in docx.ts) — correctly reflects not-implemented.

    Sharpening suggestions:

    • The Verification grep (bookmark present in docx.ts) is placement-only — a bookmark rule could exist and still lose ids through Turndown. Anchor on the outcome: a conversion test that a fixture with bookmarkStart under a heading and an internal hyperlink yields a Markdown heading whose id the #-href can target (round-trip, not a grep).
    • The reader-side half deserves its own anchor: a test that clicking a #-href naming an in-document id scrolls the pane (the navigateToHeading path), since half the fix is in the reader, not docx.ts.

    Staying open; no maintainer signal seen (zero comments, reactions, assignees).

  3. bencode commented on Oct 31, 2026

    @bencode
    OwnerAuthor

    Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. First review ran against main@d05b6b6; this beat pulled and got the same HEAD, so nothing can have moved — every citation was re-opened fresh.

  4. bencode commented on Nov 6, 2026

    @bencode
    OwnerAuthor

    Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Third pass; main is still d05b6b6 (pulled today, "Already up to date"), so nothing can have moved — every anchor was re-opened fresh regardless.

  5. bencode commented on Nov 9, 2026

    @bencode
    OwnerAuthor

    Re-audit (fourth pass) — posted by the scheduled issue-reviewer loop, independent of the authoring session. main is still d05b6b6 ("Already up to date"), so no citation can have moved; anchors re-opened regardless (docx.ts:160-188 post-processing + Turndown rules with grep -c bookmark = 0; heading-model.ts:30 positional ids; mammoth.browser.js:466-469 bookmarkStart → <a id>; file-link.tsx:18-23 / markdown.tsx:58-79 plain-anchor #-href; index.tsx:158-167,182-190). Verdict: valid, keep open (unchanged).

    Checks new this pass:

    The standing sharpening — replace the placement grep with an outcome anchor (conversion round-trip test + reader-side #-href scroll test) — remains the one open suggestion, now unaddressed across four passes.

  6. bencode commented on Nov 11, 2026

    @bencode
    OwnerAuthor

    Re-audit (fifth pass) — posted by the scheduled issue-reviewer loop, independent of the authoring session. main is still d05b6b6 (pulled today, "Already up to date"); anchors re-opened fresh — docx.ts:160-165 the five post-processing passes with grep -c bookmark = 0, mammoth.browser.js:466-469 (bookmarkStart → <a id> + forceWrite), heading-model.ts:30 positional ids. Verdict: valid, keep open (unchanged).

    Checks new this pass:

    The standing sharpening — replace the placement grep with an outcome anchor (conversion round-trip test + reader-side #-href scroll test) — remains open after five passes.

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