diff options
| author | vgmoose <me@vgmoose.com> | 2017-07-19 16:26:35 -0400 |
|---|---|---|
| committer | vgmoose <me@vgmoose.com> | 2017-07-19 17:24:11 -0400 |
| commit | 9c9cb3e30d7cae37b42537e59ba38571a9e06097 (patch) | |
| tree | aa9cc3096cdf484fcffba4a9513283cf00894ddb | |
| parent | 534f62e0684af52766adf82b8fd5dbf796e018db (diff) | |
Parse small caps style mappings (see #123)
| -rw-r--r-- | lib/document-to-html.js | 3 | ||||
| -rw-r--r-- | lib/documents.js | 1 | ||||
| -rw-r--r-- | lib/docx/body-reader.js | 3 | ||||
| -rw-r--r-- | lib/style-reader.js | 5 | ||||
| -rw-r--r-- | lib/styles/document-matchers.js | 1 | ||||
| -rw-r--r-- | test/docx/body-reader.tests.js | 14 | ||||
| -rw-r--r-- | test/style-reader.tests.js | 8 |
7 files changed, 33 insertions, 2 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index d0197cb..83e78fd 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -145,6 +145,9 @@ function DocumentConversion(options, comments) { if (run.isBold) { paths.push(findHtmlPathForRunProperty("bold", "strong")); } + if (run.isSmallCaps) { + paths.push(findHtmlPathForRunProperty("smallCaps")); + } var stylePath = htmlPaths.empty; var style = findStyle(run); if (style) { diff --git a/lib/documents.js b/lib/documents.js index 605b1b4..a6d5dd0 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -52,6 +52,7 @@ function Run(children, properties) { isUnderline: properties.isUnderline, isItalic: properties.isItalic, isStrikethrough: properties.isStrikethrough, + isSmallCaps: properties.isSmallCaps, verticalAlignment: properties.verticalAlignment || verticalAlignment.baseline, font: properties.font || null }; diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 6f6ebe2..c612e5c 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -58,7 +58,8 @@ function BodyReader(options) { isBold: readBooleanElement(element.first("w:b")), isUnderline: readBooleanElement(element.first("w:u")), isItalic: readBooleanElement(element.first("w:i")), - isStrikethrough: readBooleanElement(element.first("w:strike")) + isStrikethrough: readBooleanElement(element.first("w:strike")), + isSmallCaps: readBooleanElement(element.first("w:smallCaps")) }; }); } diff --git a/lib/style-reader.js b/lib/style-reader.js index 3a71ef6..32a2920 100644 --- a/lib/style-reader.js +++ b/lib/style-reader.js @@ -159,6 +159,8 @@ function documentMatcherRule() { // TODO: handle unknown document matchers } }); + + var smallCaps = identifierToConstant("smallCaps", documentMatchers.smallCaps); return lop.rules.firstOf("element type", paragraphOrRun, @@ -167,7 +169,8 @@ function documentMatcherRule() { underline, strikethrough, commentReference, - breakMatcher + breakMatcher, + smallCaps ); } diff --git a/lib/styles/document-matchers.js b/lib/styles/document-matchers.js index afc0a7d..3548d65 100644 --- a/lib/styles/document-matchers.js +++ b/lib/styles/document-matchers.js @@ -5,6 +5,7 @@ exports.italic = new Matcher("italic"); exports.underline = new Matcher("underline"); exports.strikethrough = new Matcher("strikethrough"); exports.commentReference = new Matcher("commentReference"); +exports.smallCaps = new Matcher("smallCaps"); exports.lineBreak = new Matcher("break", {breakType: "line"}); exports.pageBreak = new Matcher("break", {breakType: "page"}); exports.columnBreak = new Matcher("break", {breakType: "column"}); diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index 5257530..f84f0e8 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -431,11 +431,25 @@ test("isItalic is true if bold element is present", function() { assert.equal(run.isItalic, true); }); +test("isSmallCaps is false if smallcaps element is not present", function() { + var runXml = runWithProperties([]); + var run = readXmlElementValue(runXml); + assert.deepEqual(run.isSmallCaps, false); +}); + +test("isSmallCaps is true if smallcaps element is present", function() { + var smallCapsXml = new XmlElement("w:smallCaps"); + var runXml = runWithProperties([smallCapsXml]); + var run = readXmlElementValue(runXml); + assert.equal(run.isSmallCaps, true); +}); + var booleanRunProperties = [ {name: "isBold", tagName: "w:b"}, {name: "isUnderline", tagName: "w:u"}, {name: "isItalic", tagName: "w:i"}, {name: "isStrikethrough", tagName: "w:strike"}, + {name: "isSmallCaps", tagName: "w:smallCaps"}, ]; booleanRunProperties.forEach(function(runProperty) { diff --git a/test/style-reader.tests.js b/test/style-reader.tests.js index 96c0c39..2ae7385 100644 --- a/test/style-reader.tests.js +++ b/test/style-reader.tests.js @@ -185,7 +185,15 @@ test("styleReader.readDocumentMatcher", { "br[type='column']", documentMatchers.columnBreak ); + }, + + "reads smallcaps": function() { + assertDocumentMatcher( + "smallCaps", + documentMatchers.smallCaps + ); } + }); function assertDocumentMatcher(input, expected) { |
