aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-25 19:27:23 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-25 19:27:23 +0000
commit63dff589c822e8256ff8e6b38f78e696ba734c44 (patch)
tree629d432c80f829a01f3fc6e65147a25c22e416f1
parentafe8acc82adff83895c93de93c3aee889b455565 (diff)
Allow bold runs to be configured using style mapping
-rw-r--r--lib/document-to-html.js10
-rw-r--r--tests/document-to-html.tests.js17
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index 3d3e8db..ab02b64 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -107,7 +107,7 @@ function DocumentConversion(options) {
convertElements(run.children, messages, function(error, children) {
var result = Html.fragment(children);
if (run.isStrikethrough) {
- result = convertStrikethrough(result);
+ result = convertRunProperty(result, "strikethrough", "s");
}
if (run.isUnderline) {
result = convertUnderline(result);
@@ -122,7 +122,7 @@ function DocumentConversion(options) {
result = wrapInNonFreshElement(result, "em");
}
if (run.isBold) {
- result = wrapInNonFreshElement(result, "strong");
+ result = convertRunProperty(result, "bold", "strong");
}
if (style) {
result = Html.pathToNode(style.to, [result]);
@@ -139,12 +139,12 @@ function DocumentConversion(options) {
return (options.convertUnderline || defaultConvertUnderline)(runHtml);
}
- function convertStrikethrough(result) {
- var style = findStyle({type: "strikethrough"});
+ function convertRunProperty(result, elementType, defaultTagName) {
+ var style = findStyle({type: elementType});
if (style) {
return Html.pathToNode(style.to, [result]);
} else {
- return wrapInNonFreshElement(result, "s");
+ return wrapInNonFreshElement(result, defaultTagName);
}
}
diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js
index 7180191..779c584 100644
--- a/tests/document-to-html.tests.js
+++ b/tests/document-to-html.tests.js
@@ -140,7 +140,7 @@ describe('DocumentConverter', function() {
});
});
- test('bold runs are wrapped in <strong> tags', function() {
+ test('bold runs are wrapped in <strong> tags by default', function() {
var run = runOfText("Hello.", {isBold: true});
var converter = new DocumentConverter();
return converter.convertToHtml(run).then(function(result) {
@@ -148,6 +148,21 @@ describe('DocumentConverter', function() {
});
});
+ test('bold runs can be configured with style mapping', function() {
+ var run = runOfText("Hello.", {isBold: true});
+ var converter = new DocumentConverter({
+ styleMap: [
+ {
+ from: documentMatchers.bold,
+ to: htmlPaths.elements([htmlPaths.element("em")])
+ }
+ ]
+ });
+ return converter.convertToHtml(run).then(function(result) {
+ assert.equal(result.value, "<em>Hello.</em>");
+ });
+ });
+
test('bold runs can exist inside other tags', function() {
var run = new documents.Paragraph([
runOfText("Hello.", {isBold: true})