| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…eError Word writes `<w:highlight w:val="none"/>` when highlight is explicitly cleared from a run. This value is valid per ST_HighlightColor but absent from WD_COLOR_INDEX, so CT_RPr.highlight_val raised ValueError on any access to Font.highlight_color for such runs. Treat w:val="none" as "no highlight" (same semantics as the no-element case) by checking the raw attribute before the enum lookup. Fixes python-openxml#1559 Co-Authored-By: Claude <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #1559.
Reading Font.highlight_color on a run whose <w:highlight> element has w:val="none" raised ValueError: WD_COLOR_INDEX has no XML mapping for 'none'. This crashed processing of the entire document even though none is a valid ST_HighlightColor value that Word writes when explicitly clearing a highlight from a run.
Root cause
CT_RPr.highlight_val forwarded highlight.val directly to the RequiredAttribute("w:val", WD_COLOR_INDEX) descriptor, which calls WD_COLOR_INDEX.from_xml("none"). Since "none" is absent from WD_COLOR_INDEX (it has no distinct MS-API integer), from_xml raised.
Fix
Check the raw w:val attribute before the enum lookup. w:val="none" means "not highlighted" — semantically identical to the no-element case — so return None:
Testing
Added a parametrized test case ("w:r/w:rPr/w:highlight{w:val=none}", None) to it_knows_its_highlight_color. All 11 highlight-related tests pass; no regressions.
[This is Claude Code on behalf of Venkateswarlu Nagineni]