diff options
| author | Michael Williamson <mike@zwobble.org> | 2021-08-01 10:45:01 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2021-08-01 10:45:01 +0100 |
| commit | 8e88d605ae84ff3a55baf6a8c881d102e9ea1045 (patch) | |
| tree | b2f6cf39c97bdeb4c7e359175f6a22256c841b10 /lib | |
| parent | e82bdbdd8ac45f41839889188be9455100a1c17d (diff) | |
Extract raw-text module
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/index.js | 14 | ||||
| -rw-r--r-- | lib/raw-text.js | 10 |
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/index.js b/lib/index.js index 212b0b7..683352b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,6 +3,7 @@ var _ = require("underscore"); var docxReader = require("./docx/docx-reader"); var docxStyleMap = require("./docx/style-map"); var DocumentConverter = require("./document-to-html").DocumentConverter; +var convertElementToRawText = require("./raw-text").convertElementToRawText; var readStyle = require("./style-reader").readStyle; var readOptions = require("./options-reader").readOptions; var unzip = require("./unzip"); @@ -30,7 +31,7 @@ function convertToMarkdown(input, options) { function convert(input, options) { options = readOptions(options); - + return unzip.openZip(input) .tap(function(docxFile) { return docxStyleMap.readStyleMap(docxFile).then(function(styleMap) { @@ -59,7 +60,7 @@ function convertDocumentToHtml(documentResult, options) { styleMap: styleMapResult.value }); var documentConverter = new DocumentConverter(parsedOptions); - + return documentResult.flatMapThen(function(document) { return styleMapResult.flatMapThen(function(styleMap) { return documentConverter.convertToHtml(document); @@ -85,15 +86,6 @@ function extractRawText(input) { }); } -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 embedStyleMap(input, styleMap) { return unzip.openZip(input) .tap(function(docxFile) { diff --git a/lib/raw-text.js b/lib/raw-text.js new file mode 100644 index 0000000..da9a640 --- /dev/null +++ b/lib/raw-text.js @@ -0,0 +1,10 @@ +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; + } +} + +exports.convertElementToRawText = convertElementToRawText; |
