MCPcopy Create free account
hub / github.com/TruthHun/BookStack / DocumentConversion

Function DocumentConversion

static/word2md/mammoth.browser.js:139–525  ·  view source on GitHub ↗
(options, comments)

Source from the content-addressed store, hash-verified

137}
138
139function DocumentConversion(options, comments) {
140 var noteNumber = 1;
141
142 var noteReferences = [];
143
144 var referencedComments = [];
145
146 options = _.extend({ignoreEmptyParagraphs: true}, options);
147 var idPrefix = options.idPrefix === undefined ? "" : options.idPrefix;
148 var ignoreEmptyParagraphs = options.ignoreEmptyParagraphs;
149
150 var defaultParagraphStyle = htmlPaths.topLevelElement("p");
151
152 var styleMap = options.styleMap || [];
153
154 function convertToHtml(document) {
155 var messages = [];
156
157 var html = elementToHtml(document, messages, {});
158
159 var deferredNodes = [];
160 walkHtml(html, function(node) {
161 if (node.type === "deferred") {
162 deferredNodes.push(node);
163 }
164 });
165 var deferredValues = {};
166 return promises.mapSeries(deferredNodes, function(deferred) {
167 return deferred.value().then(function(value) {
168 deferredValues[deferred.id] = value;
169 });
170 }).then(function() {
171 function replaceDeferred(nodes) {
172 return flatMap(nodes, function(node) {
173 if (node.type === "deferred") {
174 return deferredValues[node.id];
175 } else if (node.children) {
176 return [
177 _.extend({}, node, {
178 children: replaceDeferred(node.children)
179 })
180 ];
181 } else {
182 return [node];
183 }
184 });
185 }
186 var writer = writers.writer({
187 prettyPrint: options.prettyPrint,
188 outputFormat: options.outputFormat
189 });
190 Html.write(writer, Html.simplify(replaceDeferred(html)));
191 return new results.Result(writer.asString(), messages);
192 });
193 }
194
195 function convertElements(elements, messages, options) {
196 return flatMap(elements, function(element) {

Callers

nothing calls this directly

Calls 10

extendMethod · 0.80
textMethod · 0.80
convertElementsFunction · 0.70
flatMapFunction · 0.70
convertCommentFunction · 0.70
htmlIdFunction · 0.70
noteHtmlIdFunction · 0.70
noteRefHtmlIdFunction · 0.70
deferredConversionFunction · 0.70
recoveringConvertImageFunction · 0.70

Tested by

no test coverage detected