Skip to content

Include stored simple-field results in paragraph text - #1655

Open
Boulea7 wants to merge 2 commits into
python-openxml:masterfrom
Boulea7:fix/paragraph-simple-field-text
Open

Boulea7 wants to merge 2 commits into
python-openxml:masterfrom
Boulea7:fix/paragraph-simple-field-text

Conversation

@Boulea7

@Boulea7 Boulea7 commented Dec 2, 2026

Copy link
Copy Markdown

Word can store the displayed text of a merge field inside w:fldSimple. Paragraph.text skipped those results, so the placeholders in #1370 disappeared when reading the document. This change reads the stored runs in order, including fields nested inside another field or hyperlink.

The reporter’s Word template has seven placeholders across the body, tables and header. All seven now match the rendered document. Reading and saving preserves the original field elements. Replacing the placeholders through Paragraph.text and reopening also preserves all seven replacement values.

All 1,613 unit tests and 650 acceptance scenarios passed. New tests cover split runs, nested fields and hyperlinks, field data, and deleted text.

Fixes #1370.

Prepared and tested with OpenAI Codex assistance.

@suirindo

suirindo commented Dec 3, 2026

Copy link
Copy Markdown

Could the iter_inner_content() docs mention that it still yields only runs and hyperlinks, so concatenating them need not match .text when a paragraph contains a simple field? In a run/field/hyperlink XML fixture with text A/B/C, the pinned selectors produce ABC for .text and AC for the iterator's elements. A documentation note would preserve the iterator's existing return types while making the difference clear. AI-assisted review; selector-level XML check only.

@Boulea7

Boulea7 commented Dec 3, 2026

Copy link
Copy Markdown
Author

I reproduced this after saving and reopening a .docx. paragraph.text returned "ABC", and the iterator yielded a run containing "A" and a hyperlink containing "C". I clarified how the iterator handles a simple field directly inside the paragraph in c56ef0d.

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.

Unable to get text of MergeFields (sometimes)

2 participants