Skip to content

feat(session): cross-references to headings and numbered items, PAGEREF, \n and \w - #1858

Open
burque505 wants to merge 2 commits into
JSv4:mainfrom
burque505:feat/cross-references
Open

burque505 wants to merge 2 commits into
JSv4:mainfrom
burque505:feat/cross-references

Conversation

@burque505

Copy link
Copy Markdown
Contributor

What

Cross-references as Word's Cross-reference dialog makes them. They can target a heading or a numbered item, as well as a bookmark.

  • AddReferenceBookmark(anchorId) puts the hidden bookmark Word allocates for such a reference over a paragraph's text. The bookmark is named _Ref plus nine digits. It covers the paragraph's text; the list number is not text, so it stays outside.
    • A _Ref bookmark that already spans exactly that text is reused, and nothing changes.
    • Otherwise the bookmark is added as one undo step.
    • The name comes back in EditResult.BookmarkName, ready for InsertCrossReference.
  • CrossReferenceOptions gains:
    • PageNumber: a PAGEREF (the target's page) instead of a REF. Its result is CachedPage; without one, the result is 1 and the field is marked dirty so Word updates it.
    • NumberNoContext (\n) and NumberFullContext (\w).
  • WmlToHtmlConverterSettings.StampReferenceFields (off by default) wraps REF, PAGEREF and NOTEREF results in data-field spans that name their bookmark. An editor can then keep each reference whole and follow it, as it already does for PAGE fields.

Surfaces

  • .NET: DocxSession.LinksBookmarks.cs, and Internal/ReferenceFieldInstr.cs for building the instruction.
  • WASM bridge and npm: addReferenceBookmark, and the new CrossReferenceOptions fields.
  • Python: add_reference_bookmark, and CrossReferenceOptions.page_number, number_no_context, number_full_context and cached_page.
  • stdio host: add_reference_bookmark, which is a mutation. insert_cross_reference takes the new options through the shared ParseCrossReferenceOptions.
  • MCP: docxodus_links action add_reference_bookmark. The new fields are in insert_cross_reference's options schema. They are new, so they have no flat aliases.
  • Op catalog: tools/op-descriptions/links-bookmarks.json.
  • CHANGELOG: under [Unreleased] → ### Added.

Tests

  • .NET:
    • DocxSessionCrossReferenceTests XR001–XR006 cover:
      • the reference bookmark spanning the paragraph and its reuse;
      • a missing anchor refused;
      • PAGEREF with the caller's page, or a dirty one;
      • the number switches (at most one, full context first);
      • the render marker on simple and complex fields;
      • parsing the three field kinds.
    • McpServerDispatcherTests.MCP156 covers add_reference_bookmark, then a PAGEREF with a cached page.
  • Python: a new test in test_links_bookmarks.py covers reuse, PAGEREF with a cached page, and REF with \n.
  • Runs: the related .NET suites and the full Python suite pass, and tsc --noEmit is clean.

🤖 Generated with Claude Code

burque505 and others added 2 commits November 23, 2026 05:14
…nce-field render marker

- AddReferenceBookmark(anchorId): the hidden _Ref bookmark (nine digits) over a whole
  paragraph's text, as Word makes for a reference to a heading or numbered item; reused
  when one already spans it.
- CrossReferenceOptions: PageNumber (PAGEREF; CachedPage from the caller, else 1 and
  dirty), NumberNoContext (\n), NumberFullContext (\w).
- WmlToHtmlConverterSettings/HtmlConversionOptions.StampReferenceFields and the editor
  render option referenceFields: REF/PAGEREF/NOTEREF results wrapped in
  span[data-field][data-field-target][data-field-hyperlink].
- WASM bridge AddReferenceBookmark; InsertCrossReference parses options with
  ParseCrossReferenceOptions; npm session.addReferenceBookmark and the new options.
- Tests XR001-XR006.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Python: add_reference_bookmark; CrossReferenceOptions page_number,
number_no_context, number_full_context, cached_page (test in
test_links_bookmarks.py). stdio: add_reference_bookmark (a mutation). MCP:
docxodus_links action add_reference_bookmark and the new insert_cross_reference
options in the schema; MCP156. links-bookmarks.json entry. npm bridge method
required. CHANGELOG entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant