diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-06-13 11:09:57 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-06-13 11:09:57 +0100 |
| commit | 700e395a3d2a0c9f6526fe7c69a92bd347fa1b88 (patch) | |
| tree | cf8ca7d2ffb52f4f1c6443a87629cbb880243a23 | |
| parent | b67feb7858174f6ab954784b92b04c6474f29047 (diff) | |
Parse run highlights
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | lib/documents.js | 3 | ||||
| -rw-r--r-- | lib/docx/body-reader.js | 3 | ||||
| -rw-r--r-- | test/docx/body-reader.tests.js | 15 |
4 files changed, 23 insertions, 2 deletions
@@ -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 cc6a2a3..c37ec05 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 7a00164..78c732e 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 5623f66..ddc060b 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]); |
