Skip to content

Include smart tag runs in paragraph and cell text - #1633

Open
binhvq wants to merge 1 commit into
python-openxml:masterfrom
binhvq:smarttag-paragraph-text
Open

binhvq wants to merge 1 commit into
python-openxml:masterfrom
binhvq:smarttag-paragraph-text

Conversation

@binhvq

@binhvq binhvq commented Oct 27, 2026

Copy link
Copy Markdown

Description

Text inside a w:smartTag element (a legacy inline wrapper Word emits for values filled from an external source, e.g. a database or XML file) was silently dropped from Paragraph.text and _Cell.text. In the example document attached to #1390, the string "0.5m" inside a table cell is wrapped in a w:smartTag and does not appear in the text reported for that cell.

This PR adds a CT_SmartTag element class whose text property joins the text of its w:r children (including runs inside nested smart tags), and includes w:smartTag children in CT_P.text so the wrapped runs are reported along with regular runs and hyperlink runs.

Verification

Fixes the issue in the document attached to #1390:

Before:

['【24#梁南侧腹板近1#台处,多处箍筋锈蚀、混凝土剥落,0.2×】']

After:

['【24#梁南侧腹板近1#台处,多处箍筋锈蚀、混凝土剥落,0.2×0.5m。】']

Full test suite passes (1606 passed; the 9 errors in tests/opc/test_phys_pkg.py also occur on unmodified master in this environment and are unrelated to this change). ruff check and ruff format --check pass on all changed files.

Disclosure

Prepared with AI assistance (Claude Code); the change was verified with the tests listed above.

Text inside a w:smartTag element (a legacy inline wrapper Word emits for
values filled from an external source) was silently dropped from
Paragraph.text and _Cell.text. Add a CT_SmartTag element class whose
text property joins its w:r children (including nested smart tags), and
include w:smartTag children in CT_P.text so the wrapped runs are
reported along with regular runs and hyperlink runs.

Fixes python-openxml#1390
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