diff --git a/NEWS b/NEWS index 4bbaca1b..5a5d9b82 100644 --- a/NEWS +++ b/NEWS @@ -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. diff --git a/lib/documents.js b/lib/documents.js index cc6a2a33..c37ec057 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -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 }; } diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 7a00164b..78c732ef 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -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"] }; }); } diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index 5623f665..ddc060b2 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -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]);