/** * Word Template Exporter * Loads word_template.docx, preserves first 2 pages (cover + TOC), * and adds markdown content starting from page 3 using template styles */ const fs = require('fs'); const path = require('path'); const PizZip = require('pizzip'); class WordTemplateExporter { /** * Path used when no explicit template is configured. Historically a * `word_template.docx` shipped at the repo root, but it was removed from * the project (see git history) while this fallback reference was not * updated, so this path is not guaranteed to exist on disk — callers * must not assume it does. Exposed as a static so the UI layer (main.js) * can check availability without duplicating the path logic. */ static getDefaultTemplatePath() { return path.join(__dirname, '../word_template.docx'); } constructor(templatePath, startPage = 3, pageSettings = null) { this.templatePath = templatePath || WordTemplateExporter.getDefaultTemplatePath(); this.startPage = startPage; // Which page to start inserting content this.pageSettings = pageSettings; // Page size and orientation settings } /** * Whether a real, readable template file exists at this.templatePath. * When false, convert() degrades gracefully to a minimal generated * document instead of throwing ENOENT. */ hasTemplateFile() { return !!this.templatePath && fs.existsSync(this.templatePath); } /** * Strip HTML artifacts that Pandoc / Word cannot render and that would * otherwise appear as visible text in DOCX output. * Removes HTML comments,