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

fix: return None for w:highlight w:val="none" instead of raising ValueError by VenkateswarluNagineni · Pull Request #1595 · 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
6 changes: 5 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,10 @@ 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's not in WD_COLOR_INDEX so we return None to match the no-element case.
if highlight.get(qn("w:val")) == "none":
return None
return highlight.val

@highlight_val.setter
Expand Down
2 changes: 2 additions & 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,8 @@ 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:val="none" is a valid ST_HighlightColor meaning "no highlight"
("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