From f7cfac642bf63fac77c99d4cc30601ded8b2c107 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 5 Nov 2020 19:35:33 +0000 Subject: Add style mapping for all caps --- lib/document-to-html.js | 3 +++ lib/documents.js | 1 + lib/docx/body-reader.js | 1 + lib/style-reader.js | 28 +++++++++++++++------------- lib/styles/document-matchers.js | 1 + 5 files changed, 21 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 2267933..32e8b03 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -130,6 +130,9 @@ function DocumentConversion(options, comments) { if (run.isSmallCaps) { paths.push(findHtmlPathForRunProperty("smallCaps")); } + if (run.isAllCaps) { + paths.push(findHtmlPathForRunProperty("allCaps")); + } if (run.isStrikethrough) { paths.push(findHtmlPathForRunProperty("strikethrough", "s")); } diff --git a/lib/documents.js b/lib/documents.js index df48beb..edc9b7c 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -59,6 +59,7 @@ function Run(children, properties) { isUnderline: properties.isUnderline, isItalic: properties.isItalic, isStrikethrough: properties.isStrikethrough, + isAllCaps: properties.isAllCaps, 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 ad4f409..77f194b 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -73,6 +73,7 @@ function BodyReader(options) { isUnderline: readUnderline(element.first("w:u")), isItalic: readBooleanElement(element.first("w:i")), isStrikethrough: readBooleanElement(element.first("w:strike")), + isAllCaps: readBooleanElement(element.first("w:caps")), isSmallCaps: readBooleanElement(element.first("w:smallCaps")) }; }); diff --git a/lib/style-reader.js b/lib/style-reader.js index f686b28..07521ad 100644 --- a/lib/style-reader.js +++ b/lib/style-reader.js @@ -39,7 +39,7 @@ function readDocumentMatcher(string) { function documentMatcherRule() { var sequence = lop.rules.sequence; - + var identifierToConstant = function(identifier, constant) { return lop.rules.then( lop.rules.token("identifier", identifier), @@ -48,15 +48,15 @@ function documentMatcherRule() { } ); }; - + var paragraphRule = identifierToConstant("p", documentMatchers.paragraph); var runRule = identifierToConstant("r", documentMatchers.run); - + var elementTypeRule = lop.rules.firstOf("p or r or table", paragraphRule, runRule ); - + var styleIdRule = lop.rules.then( classRule, function(styleId) { @@ -86,7 +86,7 @@ function documentMatcherRule() { } ) ); - + var styleNameRule = lop.rules.sequence( lop.rules.tokenOfType("open-square-bracket"), lop.rules.sequence.cut(), @@ -95,7 +95,7 @@ function documentMatcherRule() { lop.rules.tokenOfType("close-square-bracket") ).head(); - + var listTypeRule = lop.rules.firstOf("list type", identifierToConstant("ordered-list", {isOrdered: true}), identifierToConstant("unordered-list", {isOrdered: false}) @@ -130,7 +130,7 @@ function documentMatcherRule() { return matcherOptions; }); } - + var paragraphOrRun = sequence( sequence.capture(elementTypeRule), sequence.capture(createMatcherSuffixesRule([ @@ -141,7 +141,7 @@ function documentMatcherRule() { ).map(function(createMatcher, matcherOptions) { return createMatcher(matcherOptions); }); - + var table = sequence( lop.rules.token("identifier", "table"), sequence.capture(createMatcherSuffixesRule([ @@ -156,9 +156,10 @@ function documentMatcherRule() { var italic = identifierToConstant("i", documentMatchers.italic); var underline = identifierToConstant("u", documentMatchers.underline); var strikethrough = identifierToConstant("strike", documentMatchers.strikethrough); + var allCaps = identifierToConstant("all-caps", documentMatchers.allCaps); var smallCaps = identifierToConstant("small-caps", documentMatchers.smallCaps); var commentReference = identifierToConstant("comment-reference", documentMatchers.commentReference); - + var breakMatcher = sequence( lop.rules.token("identifier", "br"), sequence.cut(), @@ -187,6 +188,7 @@ function documentMatcherRule() { italic, underline, strikethrough, + allCaps, smallCaps, commentReference, breakMatcher @@ -211,7 +213,7 @@ function htmlPathRule() { }).valueOrElse(false); } ); - + var separatorRule = lop.rules.then( lop.rules.optional(lop.rules.sequence( lop.rules.tokenOfType("colon"), @@ -229,7 +231,7 @@ function htmlPathRule() { identifierRule, lop.rules.tokenOfType("choice") ); - + var styleElementRule = lop.rules.sequence( capture(tagNamesRule), capture(lop.rules.zeroOrMore(classRule)), @@ -249,7 +251,7 @@ function htmlPathRule() { } return htmlPaths.element(tagName, attributes, options); }); - + return lop.rules.firstOf("html path", lop.rules.then(lop.rules.tokenOfType("bang"), function() { return htmlPaths.ignore; @@ -267,7 +269,7 @@ function htmlPathRule() { ) ); } - + var identifierRule = lop.rules.then( lop.rules.tokenOfType("identifier"), decodeEscapeSequences diff --git a/lib/styles/document-matchers.js b/lib/styles/document-matchers.js index 11b577f..005e2db 100644 --- a/lib/styles/document-matchers.js +++ b/lib/styles/document-matchers.js @@ -5,6 +5,7 @@ exports.bold = new Matcher("bold"); exports.italic = new Matcher("italic"); exports.underline = new Matcher("underline"); exports.strikethrough = new Matcher("strikethrough"); +exports.allCaps = new Matcher("allCaps"); exports.smallCaps = new Matcher("smallCaps"); exports.commentReference = new Matcher("commentReference"); exports.lineBreak = new Matcher("break", {breakType: "line"}); -- cgit v1.2.3