diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-06-17 15:32:53 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-06-17 15:35:22 +0100 |
| commit | dc53892204989de1788081624c65062dc283480a (patch) | |
| tree | 5efcf80db1a80eb06f29d5c03cdeb97823f1085b | |
| parent | 511f6787dd943fc8a9321bd0e3464eb1e0eef11b (diff) | |
Add support for strikethrough
| -rw-r--r-- | lib/document-to-html.js | 3 | ||||
| -rw-r--r-- | lib/documents.js | 1 | ||||
| -rw-r--r-- | lib/docx/document-xml-reader.js | 1 | ||||
| -rw-r--r-- | tests/document-to-html.tests.js | 8 | ||||
| -rw-r--r-- | tests/docx/document-xml-reader.tests.js | 13 | ||||
| -rw-r--r-- | tests/mammoth.tests.js | 7 | ||||
| -rwxr-xr-x | tests/test-data/strikethrough.docx | bin | 0 -> 12652 bytes |
7 files changed, 33 insertions, 0 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 264f7c9..f424acf 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -125,6 +125,9 @@ function DocumentConversion(options) { if (run.isUnderline) { convertUnderline(runHtml); } + if (run.isStrikethrough) { + runHtml.open(htmlPaths.element("s")); + } convertElements(run.children, runHtml, messages, function(err) { if (err) { callback(err); diff --git a/lib/documents.js b/lib/documents.js index 10d8646..4e4211b 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -48,6 +48,7 @@ function Run(children, properties) { isBold: properties.isBold, isUnderline: properties.isUnderline, isItalic: properties.isItalic, + isStrikethrough: properties.isStrikethrough, verticalAlignment: properties.verticalAlignment || verticalAlignment.baseline }; } diff --git a/lib/docx/document-xml-reader.js b/lib/docx/document-xml-reader.js index 8bdb8cc..1d36d91 100644 --- a/lib/docx/document-xml-reader.js +++ b/lib/docx/document-xml-reader.js @@ -75,6 +75,7 @@ function DocumentXmlReader(options) { properties.isBold = !!element.first("w:b"); properties.isUnderline = !!element.first("w:u"); properties.isItalic = !!element.first("w:i"); + properties.isStrikethrough = !!element.first("w:strike"); return elementResult(properties); } diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index 516f2fe..02079cd 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -202,6 +202,14 @@ describe('DocumentConverter', function() { }); }); + test('strikethrough runs are wrapped in <s> tags by default', function() { + var run = runOfText("Hello.", {isStrikethrough: true}); + var converter = new DocumentConverter(); + return converter.convertToHtml(run).then(function(result) { + assert.equal(result.value, "<s>Hello.</s>"); + }); + }); + test('style mapping for underline runs does not close parent elements', function() { var run = runOfText("Hello.", {isUnderline: true, isBold: true}); var converter = new DocumentConverter({ diff --git a/tests/docx/document-xml-reader.tests.js b/tests/docx/document-xml-reader.tests.js index 4e1da69..dee31b0 100644 --- a/tests/docx/document-xml-reader.tests.js +++ b/tests/docx/document-xml-reader.tests.js @@ -152,6 +152,19 @@ describe("readXmlElement: ", function() { assert.equal(run.isUnderline, true); }); + test("isStrikethrough is false if strikethrough element is not present", function() { + var runXml = runWithProperties([]); + var run = readXmlElementValue(runXml); + assert.deepEqual(run.isStrikethrough, false); + }); + + test("isStrikethrough is true if strikethrough element is present", function() { + var strikethroughXml = new XmlElement("w:strike"); + var runXml = runWithProperties([strikethroughXml]); + var run = readXmlElementValue(runXml); + assert.equal(run.isStrikethrough, true); + }); + test("isItalic is false if bold element is not present", function() { var runXml = runWithProperties([]); var run = readXmlElementValue(runXml); diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js index 93fc966..cdc14e5 100644 --- a/tests/mammoth.tests.js +++ b/tests/mammoth.tests.js @@ -224,6 +224,13 @@ describe('mammoth', function() { }); }); + test('strikethrough is converted to <s> by default', function() { + var docxPath = path.join(__dirname, "test-data/strikethrough.docx"); + return mammoth.convertToHtml({path: docxPath}).then(function(result) { + assert.equal(result.value, "<p><s>Today's Special: Salmon</s> Sold out</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/test-data/strikethrough.docx b/tests/test-data/strikethrough.docx Binary files differnew file mode 100755 index 0000000..0d2b713 --- /dev/null +++ b/tests/test-data/strikethrough.docx |
