prosemirror-docx
Version:
Export from a prosemirror document to Microsoft word
51 lines • 1.83 kB
JavaScript
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());
});
};
import { Document, Packer, SectionType } from 'docx';
export function createShortId() {
return Math.random().toString(36).substr(2, 9);
}
export function createDocFromState(state) {
const doc = new Document({
footnotes: state.footnotes,
numbering: {
config: state.numbering,
},
sections: [
{
properties: {
type: SectionType.CONTINUOUS,
},
children: state.children,
},
],
});
return doc;
}
export function writeDocx(doc,
/**
* @deprecated use `.then()` or `await` instead
*/
write) {
return __awaiter(this, void 0, void 0, function* () {
const buffer = yield Packer.toBuffer(doc);
yield (write === null || write === void 0 ? void 0 : write(buffer));
return buffer;
});
}
export 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;
}
//# sourceMappingURL=utils.js.map