summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvgmoose <me@vgmoose.com>2017-07-21 00:04:49 -0400
committervgmoose <me@vgmoose.com>2017-07-21 00:04:49 -0400
commit33f089bb9f1d8fa599fe10ba1ddead6c10dbd4b4 (patch)
tree40b6f218fbbac7782effb8b0ab1255b3e773a315
parent9c9cb3e30d7cae37b42537e59ba38571a9e06097 (diff)
Rename smallCaps style mapping to small-caps
-rw-r--r--lib/document-to-html.js6
-rw-r--r--lib/style-reader.js7
-rw-r--r--lib/styles/document-matchers.js2
-rw-r--r--test/document-to-html.tests.js24
-rw-r--r--test/style-reader.tests.js16
5 files changed, 39 insertions, 16 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index 83e78fd..0dac05e 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -127,6 +127,9 @@ function DocumentConversion(options, comments) {
return convertElements(run.children, messages, options);
};
var paths = [];
+ if (run.isSmallCaps) {
+ paths.push(findHtmlPathForRunProperty("smallCaps"));
+ }
if (run.isStrikethrough) {
paths.push(findHtmlPathForRunProperty("strikethrough", "s"));
}
@@ -145,9 +148,6 @@ 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/style-reader.js b/lib/style-reader.js
index 32a2920..692672e 100644
--- a/lib/style-reader.js
+++ b/lib/style-reader.js
@@ -137,6 +137,7 @@ function documentMatcherRule() {
var italic = identifierToConstant("i", documentMatchers.italic);
var underline = identifierToConstant("u", documentMatchers.underline);
var strikethrough = identifierToConstant("strike", documentMatchers.strikethrough);
+ var smallCaps = identifierToConstant("small-caps", documentMatchers.smallCaps);
var commentReference = identifierToConstant("comment-reference", documentMatchers.commentReference);
var breakMatcher = sequence(
@@ -160,17 +161,15 @@ function documentMatcherRule() {
}
});
- var smallCaps = identifierToConstant("smallCaps", documentMatchers.smallCaps);
-
return lop.rules.firstOf("element type",
paragraphOrRun,
bold,
italic,
underline,
strikethrough,
+ smallCaps,
commentReference,
- breakMatcher,
- smallCaps
+ breakMatcher
);
}
diff --git a/lib/styles/document-matchers.js b/lib/styles/document-matchers.js
index 3548d65..e3cae46 100644
--- a/lib/styles/document-matchers.js
+++ b/lib/styles/document-matchers.js
@@ -4,8 +4,8 @@ exports.bold = new Matcher("bold");
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.commentReference = new Matcher("commentReference");
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/document-to-html.tests.js b/test/document-to-html.tests.js
index bf6631f..861033b 100644
--- a/test/document-to-html.tests.js
+++ b/test/document-to-html.tests.js
@@ -296,6 +296,30 @@ test('subscript runs are wrapped in <sub> tags', function() {
});
});
+test('small caps runs are ignored by default', function() {
+ var run = runOfText("Hello.", {isSmallCaps: true});
+ var converter = new DocumentConverter();
+ return converter.convertToHtml(run).then(function(result) {
+ assert.equal(result.value, "Hello.");
+ });
+});
+
+test('small caps runs can be configured with style mapping', function() {
+ var run = runOfText("Hello.", {isSmallCaps: true});
+ var converter = new DocumentConverter({
+ styleMap: [
+ {
+ from: documentMatchers.smallCaps,
+ to: htmlPaths.elements([htmlPaths.element("span")])
+ }
+ ]
+ });
+ return converter.convertToHtml(run).then(function(result) {
+ assert.equal(result.value, "<span>Hello.</span>");
+ });
+});
+
+
test('run styles are converted to HTML if mapping exists', function() {
var run = runOfText("Hello.", {styleId: "Heading1Char", styleName: "Heading 1 Char"});
var converter = new DocumentConverter({
diff --git a/test/style-reader.tests.js b/test/style-reader.tests.js
index 2ae7385..20d4127 100644
--- a/test/style-reader.tests.js
+++ b/test/style-reader.tests.js
@@ -159,6 +159,13 @@ test("styleReader.readDocumentMatcher", {
);
},
+ "reads smallcaps": function() {
+ assertDocumentMatcher(
+ "small-caps",
+ documentMatchers.smallCaps
+ );
+ },
+
"reads comment-reference": function() {
assertDocumentMatcher(
"comment-reference",
@@ -185,15 +192,8 @@ test("styleReader.readDocumentMatcher", {
"br[type='column']",
documentMatchers.columnBreak
);
- },
-
- "reads smallcaps": function() {
- assertDocumentMatcher(
- "smallCaps",
- documentMatchers.smallCaps
- );
}
-
+
});
function assertDocumentMatcher(input, expected) {