Skip to content

Commit

Permalink
Handle highlight value of none
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Jun 13, 2024
1 parent 5edcc79 commit 8f95839
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ private Optional<HyperlinkComplexField> currentHyperlinkComplexField() {
}

private Optional<String> readHighlight(XmlElementLike properties) {
return readVal(properties, "w:highlight");
return readVal(properties, "w:highlight")
.filter(value -> !value.isEmpty() && !value.equals("none"));
}

private boolean isBold(XmlElementLike properties) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,17 @@ public void runHasHighlightReadFromProperties() {
assertThat(result, hasProperty("highlight", equalTo(Optional.of("yellow"))));
}

@Test
public void whenHighlightIsNoneThenRunhasNoHighlight() {
XmlElement element = runXmlWithProperties(
element("w:highlight", map("w:val", "none"))
);

DocumentElement result = readSuccess(bodyReader(), element);

assertThat(result, hasProperty("highlight", equalTo(Optional.empty())));
}

@Test
public void canReadTabElement() {
XmlElement element = element("w:tab");
Expand Down

0 comments on commit 8f95839

Please sign in to comment.