Skip to content

Expand self-closing tcPr before inserting gridSpan and shd - #656

Open
zxyasfas wants to merge 1 commit into
elapouya:masterfrom
zxyasfas:fix-selfclosing-tcpr
Open

Expand self-closing tcPr before inserting gridSpan and shd#656
zxyasfas wants to merge 1 commit into
elapouya:masterfrom
zxyasfas:fix-selfclosing-tcpr

Conversation

@zxyasfas

Copy link
Copy Markdown

Fixes #559.

Pandoc (and some other producers) collapse empty cell properties to a self-closing <w:tcPr/>. The insertion regex in colspan() and cellbg() matches that form too ([^>]* eats the /), so <w:gridSpan> / <w:shd> end up as a sibling after the closed element instead of inside it. That position is schema-invalid and Word silently drops it, which matches the silent breakage reported in the issue.

The fix expands a self-closing <w:tcPr/> (attributes preserved) into an open/close pair before the existing insertion runs. Templates that already have an expanded <w:tcPr> go through exactly the same path as before.

Added tests/cellbg_selfclosing.py covering cellbg and colspan against a self-closing tcPr, one with attributes, and the already-expanded form. It asserts on patch_xml output directly so it needs no template file. Ran the rest of the tests dir locally, all green.

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.

Cell background tags do not work in docx files with shorthand tags (i.e., with <w:tcPr /> instead of <w:tcPr>...</w:tcPr>)

1 participant