FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: map highlight w:val="none" to None instead of raising by mithunvoe · Pull Request #1560 · python-openxml/python-docx · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 7 additions & 1 deletion src/docx/oxml/text/font.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from docx.enum.dml import MSO_THEME_COLOR
from docx.enum.text import WD_COLOR_INDEX, WD_UNDERLINE
from docx.oxml.ns import nsdecls
from docx.oxml.ns import nsdecls, qn
from docx.oxml.parser import parse_xml
from docx.oxml.simpletypes import (
ST_HexColor,
Expand Down Expand Up @@ -159,6 +159,12 @@ def highlight_val(self) -> WD_COLOR_INDEX | None:
highlight = self.highlight
if highlight is None:
return None
# -- `w:val="none"` is a valid `ST_HighlightColor` value meaning "no
# -- highlight". It has no `WD_COLOR_INDEX` member, so map it to `None`
# -- (the same value used when no `w:highlight` element is present)
# -- rather than raising on the unmapped value.
if highlight.get(qn("w:val")) == "none":
return None
return highlight.val

@highlight_val.setter
Expand Down
1 change: 1 addition & 0 deletions tests/text/test_font.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def it_can_change_its_underline_type(
("w:r/w:rPr", None),
("w:r/w:rPr/w:highlight{w:val=default}", WD_COLOR.AUTO),
("w:r/w:rPr/w:highlight{w:val=blue}", WD_COLOR.BLUE),
("w:r/w:rPr/w:highlight{w:val=none}", None),
],
)
def it_knows_its_highlight_color(self, r_cxml: str, expected_value: WD_COLOR | None):
Expand Down

Back | FazBrowse Home | New Git URL