aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-07-06 17:52:24 +0100
committerMichael Williamson <mike@zwobble.org>2014-07-06 17:52:24 +0100
commit2550dfe6a8cd777a6c21ce8ae6c0a99b7f26aced (patch)
treec24ce9e95b38de9505d246f37cdb4e6f5fc386f2 /lib
parentdef56988014ad3654185261ebb1bf4208cc3b6d8 (diff)
Add extractRawText function
Diffstat (limited to 'lib')
-rw-r--r--lib/index.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/index.js b/lib/index.js
index 35bcbaf..879327f 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -4,6 +4,7 @@ var readStyle = require("./style-reader").readStyle;
var readOptions = require("./options-reader").readOptions;
exports.convertToHtml = convertToHtml;
+exports.extractRawText = extractRawText;
function convertToHtml(input, options) {
var fullOptions = readOptions(options);
@@ -26,6 +27,30 @@ function convertDocumentToHtml(documentResult, options) {
});
}
+
+function extractRawText(input) {
+ return docxReader.read(input)
+ .then(function(documentResult) {
+ return documentResult.map(convertElementToRawText);
+ });
+}
+
+function convertElementToRawText(element) {
+ if (element.type === "text") {
+ return element.value;
+ } else {
+ var tail = element.type === "paragraph" ? "\n\n" : "";
+ return (element.children || []).map(convertElementToRawText).join("") + tail;
+ }
+}
+
+function convertElements(elements, html, messages, callback) {
+ async.eachSeries(elements, function(element, callback) {
+ return elementToHtml(element, html, messages, callback);
+ }, callback);
+}
+
+
exports.styleMapping = function() {
throw new Error('Use a raw string instead of mammoth.styleMapping e.g. "p[style-naming=\'Title\'] => h1" instead of mammoth.styleMapping("p[style-naming=\'Title\'] => h1")');
};