Skip to content

Commit

Permalink
Parse run highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Jun 13, 2024
1 parent b67feb7 commit 700e395
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.8.0

* Support parsing of run highlights.

# 1.7.2

* Remove the use of the path module from common code used by browser builds.
Expand Down
3 changes: 2 additions & 1 deletion lib/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function Run(children, properties) {
isSmallCaps: !!properties.isSmallCaps,
verticalAlignment: properties.verticalAlignment || verticalAlignment.baseline,
font: properties.font || null,
fontSize: properties.fontSize || null
fontSize: properties.fontSize || null,
highlight: properties.highlight || null
};
}

Expand Down
3 changes: 2 additions & 1 deletion lib/docx/body-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ function BodyReader(options) {
isItalic: readBooleanElement(element.first("w:i")),
isStrikethrough: readBooleanElement(element.first("w:strike")),
isAllCaps: readBooleanElement(element.first("w:caps")),
isSmallCaps: readBooleanElement(element.first("w:smallCaps"))
isSmallCaps: readBooleanElement(element.first("w:smallCaps")),
highlight: element.firstOrEmpty("w:highlight").attributes["w:val"]
};
});
}
Expand Down
15 changes: 15 additions & 0 deletions test/docx/body-reader.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,21 @@ test("run with invalid w:sz has null font size", function() {
assert.deepEqual(run.fontSize, null);
});

test("run has no highlight by default", function() {
var runXml = runWithProperties([]);

var run = readXmlElementValue(runXml);
assert.deepEqual(run.highlight, null);
});

test("run has highlight read from properties", function() {
var fontXml = new XmlElement("w:highlight", {"w:val": "yellow"});
var runXml = runWithProperties([fontXml]);

var run = readXmlElementValue(runXml);
assert.deepEqual(run.highlight, "yellow");
});

test("run properties not included as child of run", function() {
var runStyleXml = new XmlElement("w:rStyle");
var runPropertiesXml = new XmlElement("w:rPr", {}, [runStyleXml]);
Expand Down

0 comments on commit 700e395

Please sign in to comment.