aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-06-17 14:33:43 +0100
committerMichael Williamson <mike@zwobble.org>2015-06-17 14:33:43 +0100
commit17577bdd715c65e71d81f762b54b8c27f60f4535 (patch)
tree5389d7741881b2d198daf450f915fa9b3527f7e7 /tests
parentdc31bacddd43e100a2793c76e26d35568262d89a (diff)
Support underlines in style map
Diffstat (limited to 'tests')
-rw-r--r--tests/document-to-html.tests.js32
-rw-r--r--tests/html-generator.tests.js9
-rw-r--r--tests/mammoth.tests.js7
-rw-r--r--tests/style-reader.tests.js7
4 files changed, 54 insertions, 1 deletions
diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js
index 5a271d0..516f2fe 100644
--- a/tests/document-to-html.tests.js
+++ b/tests/document-to-html.tests.js
@@ -177,7 +177,7 @@ describe('DocumentConverter', function() {
});
});
- test('underline runs can be wrapped in <u> tags', function() {
+ test('underline runs can be wrapped in <u> tags using convertUnderline option', function() {
var run = runOfText("Hello.", {isUnderline: true});
var converter = new DocumentConverter({
convertUnderline: mammoth.underline.element("u")
@@ -186,6 +186,36 @@ describe('DocumentConverter', function() {
assert.equal(result.value, "<u>Hello.</u>");
});
});
+
+ test('underline runs can be mapped using style mapping', function() {
+ var run = runOfText("Hello.", {isUnderline: true});
+ var converter = new DocumentConverter({
+ styleMap: [
+ {
+ from: documentMatchers.underline,
+ to: htmlPaths.elements([htmlPaths.element("u")])
+ }
+ ]
+ });
+ return converter.convertToHtml(run).then(function(result) {
+ assert.equal(result.value, "<u>Hello.</u>");
+ });
+ });
+
+ test('style mapping for underline runs does not close parent elements', function() {
+ var run = runOfText("Hello.", {isUnderline: true, isBold: true});
+ var converter = new DocumentConverter({
+ styleMap: [
+ {
+ from: documentMatchers.underline,
+ to: htmlPaths.elements([htmlPaths.element("u")])
+ }
+ ]
+ });
+ return converter.convertToHtml(run).then(function(result) {
+ assert.equal(result.value, "<strong><u>Hello.</u></strong>");
+ });
+ });
test('italic runs are wrapped in <em> tags', function() {
var run = runOfText("Hello.", {isItalic: true});
diff --git a/tests/html-generator.tests.js b/tests/html-generator.tests.js
index f361633..6921b45 100644
--- a/tests/html-generator.tests.js
+++ b/tests/html-generator.tests.js
@@ -69,4 +69,13 @@ describe('HtmlGenerator', function() {
generator.selfClosing({tagName: "br", attributes: {"data-blah": "<"}});
return assert.equal(generator.asString(), '<br data-blah="&lt;" />');
});
+
+ test('appendPath does not close currently-open elements', function() {
+ var generator = new HtmlGenerator();
+ generator.satisfyPath(htmlPaths.elements(["strong"]));
+ generator.appendPath(htmlPaths.elements(["em"]));
+ generator.text("Hello!");
+ generator.closeAll();
+ return assert.equal(generator.asString(), "<strong><em>Hello!</em></strong>");
+ });
});
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index e016fe1..93fc966 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -217,6 +217,13 @@ describe('mammoth', function() {
});
});
+ test('underline can be configured with style mapping', function() {
+ var docxPath = path.join(__dirname, "test-data/underline.docx");
+ return mammoth.convertToHtml({path: docxPath}, {styleMap: "u => em"}).then(function(result) {
+ assert.equal(result.value, '<p><strong>The </strong><strong><em>Sunset</em></strong><strong> Tree</strong></p>');
+ });
+ });
+
test('indentation is used if prettyPrint is true', function() {
var docxPath = path.join(__dirname, "test-data/single-paragraph.docx");
return mammoth.convertToHtml({path: docxPath}, {prettyPrint: true}).then(function(result) {
diff --git a/tests/style-reader.tests.js b/tests/style-reader.tests.js
index 7927153..59d7c51 100644
--- a/tests/style-reader.tests.js
+++ b/tests/style-reader.tests.js
@@ -93,6 +93,13 @@ describe("styleReader.readDocumentMatcher", function() {
documentMatchers.run()
);
});
+
+ test("reads underline", function() {
+ assert.deepEqual(
+ readDocumentMatcher("u"),
+ documentMatchers.underline
+ );
+ });
});
describe("styleReader.read", function() {