Skip to content

fix: return None for highlight_color when w:val is 'none' - #1581

Open
ChenfromChina123 wants to merge 2 commits into
python-openxml:masterfrom
ChenfromChina123:fix/highlight-none-color
Open

fix: return None for highlight_color when w:val is 'none'#1581
ChenfromChina123 wants to merge 2 commits into
python-openxml:masterfrom
ChenfromChina123:fix/highlight-none-color

Conversation

@ChenfromChina123

Copy link
Copy Markdown

What does this PR do?

Fixes ValueError: WD_COLOR_INDEX has no XML mapping for 'none' when reading Font.highlight_color on a run whose <w:highlight> element has w:val="none". none is a valid ST_HighlightColor value — Word writes it when a highlight is explicitly cleared.

Closes #1559

Changes

  • src/docx/oxml/text/font.py: CT_RPr.highlight_val now returns None when the raw attribute is "none" instead of attempting an enum conversion.

Verification

  • python -m py_compile src/docx/oxml/text/font.py passes.

ChenfromChina123 and others added 2 commits August 10, 2026 22:34
The example calls add_picture('monty-truth.png') which raises
FileNotFoundError when the file is not present in the working
directory. Wrap it in a try/except so the example runs out of
the box.

Closes python-openxml#128

Co-Authored-By: AtomCode (deepseek-v4-flash) <noreply@atomgit.com>
w:val="none" is a valid ST_HighlightColor value meaning the
highlight is explicitly cleared, but it has no WD_COLOR_INDEX
mapping, so reading font.highlight_color raised ValueError.

Closes python-openxml#1559

Co-Authored-By: AtomCode (deepseek-v4-flash) <noreply@atomgit.com>
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.

Reading Font.highlight_color raises ValueError for valid w:highlight w:val="none"

1 participant