import { Document, Packer, // Paragraph, // TableOfContents } from "docx" import globalConfig from "./globalConfig" import { handleElement, getTitle, getConfig } from "./handleElement" export async function exportDomToWord(domSelector: string = ".content") { const dom = document.querySelector(domSelector) if (!dom) { console.warn("未找到内容区域") return } const paragraphs = await handleElement(dom) // 构建 Word 文档 const doc = new Document({ title: getTitle(), ...globalConfig, ...getConfig(), sections: [{ children: [ // 暂时不使用目录 // new Paragraph("文档目录如下:"), // new TableOfContents("目录", { // hyperlink: true, // headingStyleRange: "1-3", // 收录 Heading 1~3 // }), ...paragraphs ] }], }) const blob = await Packer.toBlob(doc) return blob }