Skip to content

fix(docx): preserve field display text (fldSimple, MACROBUTTON) - #2553

Open
Rohan Patnaik (rohan-patnaik) wants to merge 1 commit into
microsoft:mainfrom
rohan-patnaik:fix/docx-field-text
Open

Rohan Patnaik (rohan-patnaik) wants to merge 1 commit into
microsoft:mainfrom
rohan-patnaik:fix/docx-field-text

Conversation

@rohan-patnaik

@rohan-patnaik Rohan Patnaik (rohan-patnaik) commented Sep 24, 2026 •

Copy link
Copy Markdown

Fixes #1247.

Summary

DOCX conversion dropped visible text from simple fields and separator-less MACROBUTTON fields. This adds a preprocessing step that:

  • unwraps w:fldSimple cached result runs, using the MACROBUTTON display argument only when needed;
  • converts display text from separator-less complex MACROBUTTON fields without exposing other field instructions; and
  • handles document, footnote, and endnote parts.

Tests

  • New field regressions fail on unmodified b8f79c5 and pass here.
  • Full suite: 997 passed, 14 skipped, with one unrelated environmental failure reproduced on the base.
  • Fieldless documents remain byte-identical.

The reporter's currently hosted 3GPP sample no longer contains fields, so this fixes the field-loss mechanism without changing that reprocessed file.

Mammoth has no handler for w:fldSimple, so simple fields are dropped
along with the child runs holding their cached result, and it never
emits field instructions, so MACROBUTTON fields (whose display text is
the trailing argument of the instruction, with no result runs) vanish
entirely. Text carried in Word fields was silently missing from the
Markdown output.

Add a _pre_process_fields step for document/footnotes/endnotes XML that
unwraps w:fldSimple elements so their cached result runs convert like
ordinary content, and rewrites the MACROBUTTON instruction of fields
without a separator (simple or complex) into text runs holding only the
display-text argument. Other instructions are still never emitted, and
complex fields with a separator are untouched since Mammoth already
converts their result runs.

Fixes microsoft#1247
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.

Failed to convert text in macros (.docx to .md)

1 participant