UNPKG

prosemirror-docx

Version:

Export from a prosemirror document to Microsoft word

58 lines 2.15 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLatexFromNode = exports.writeDocx = exports.createDocFromState = exports.createShortId = void 0; const docx_1 = require("docx"); function createShortId() { return Math.random().toString(36).substr(2, 9); } exports.createShortId = createShortId; function createDocFromState(state) { const doc = new docx_1.Document({ footnotes: state.footnotes, numbering: { config: state.numbering, }, sections: [ { properties: { type: docx_1.SectionType.CONTINUOUS, }, children: state.children, }, ], }); return doc; } exports.createDocFromState = createDocFromState; function writeDocx(doc, /** * @deprecated use `.then()` or `await` instead */ write) { return __awaiter(this, void 0, void 0, function* () { const buffer = yield docx_1.Packer.toBuffer(doc); yield (write === null || write === void 0 ? void 0 : write(buffer)); return buffer; }); } exports.writeDocx = writeDocx; function getLatexFromNode(node) { let math = ''; node.forEach((child) => { if (child.isText) math += child.text; // TODO: improve this as we may have other things in the future }); return math; } exports.getLatexFromNode = getLatexFromNode; //# sourceMappingURL=utils.js.map