Commit ce390d3
committed
fix: map highlight w:val="none" to None instead of raising
`w:val="none"` is a valid `ST_HighlightColor` value that Word writes when
a highlight is explicitly cleared from a run. It has no `WD_COLOR_INDEX`
member, so reading `Font.highlight_color` on such a run raised
`ValueError: WD_COLOR_INDEX has no XML mapping for 'none'` from
`BaseXmlEnum.from_xml()`, which aborts parsing of any document containing
the value.
`none` semantically means "not highlighted", which python-docx already
represents as `None` (the value returned when no `w:highlight` element is
present), and which the `highlight_val` setter writes by removing the
element. Map the explicit `none` value to `None` in the getter to match.
`none` is the only `ST_HighlightColor` value absent from `WD_COLOR_INDEX`,
so this closes the gap completely.1 parent e454546 commit ce390d3
2 files changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
162 | 168 | | |
163 | 169 | | |
164 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| 384 | + | |
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
| |||
0 commit comments