UNPKG

myst-to-docx

Version:

Export from a MyST Markdown document to Microsoft Word (*.docx)

22 lines (21 loc) 625 B
import { Packer } from 'docx'; import { DocxSerializer } from './serializer.js'; import { createDocFromState } from './utils.js'; export const plugin = function (opts) { this.Compiler = (node, file) => { const state = new DocxSerializer(file, opts); state.renderChildren(node); const doc = createDocFromState(state); if (typeof document === 'undefined') { file.result = Packer.toBuffer(doc); } else { file.result = Packer.toBlob(doc); } return file; }; return (node) => { // Preprocess return node; }; };