diff --git a/src/main.js b/src/main.js index 5af28a6..1acac86 100644 --- a/src/main.js +++ b/src/main.js @@ -8,6 +8,7 @@ const PDFOperations = require('./main/PDFOperations'); const GitOperations = require('./main/GitOperations'); const PdfFontHeader = require('./main/PdfFontHeader'); const MonospaceFontConfig = require('./main/MonospaceFontConfig'); +const ExportCss = require('./main/ExportCss'); // Add MiKTeX to PATH for LaTeX support if (process.platform === 'win32') { @@ -335,6 +336,22 @@ function buildMonospaceHeaderFile() { return headerFile; } +// Build a self-contained CSS fragment for HTML/EPUB exports that embeds +// the active monospace font as a base64 data URI. Returns a string with a +// trailing newline suitable for either inline injection or a temp file. +function buildMonospaceExportCss() { + const s = readSettingsJsonCached(); + const familyKey = s.monospaceFont || 'jetbrains-mono'; + const family = familyKey === 'fira-code' ? 'Fira Code' : 'JetBrains Mono'; + const monoFontPath = MonospaceFontConfig.getMonoFontTtfPath(familyKey, 400); + return ExportCss.build({ + activeFontPath: monoFontPath, + family, + weight: 400, + ligatures: !!s.monospaceLigatures, + }); +} + // Plugin settings IPC handlers ipcMain.handle('plugin-settings:get', (_event, key) => { return store.get(key); @@ -2764,6 +2781,12 @@ function performExportWithOptions(format, options) { } else if (format === 'json') { pandocCmd = `${getPandocPath()} "${currentFile}" -t json -o "${outputFile}"`; exportWithPandoc(pandocCmd, outputFile, format); + } else if (format === 'html') { + // Build a complete HTML file with our bundled monospace font as embedded CSS. + const cssFile = path.join(os.tmpdir(), `monospace-html-${Date.now()}-${process.pid}.css`); + fs.writeFileSync(cssFile, buildMonospaceExportCss(), 'utf-8'); + pandocCmd = `${getPandocPath()} "${inputFile}" -s --css="${cssFile}" -o "${outputFile}"`; + exportWithPandoc(pandocCmd, outputFile, format); } else if (format === 'yaml' || format === 'xml' || format === 'toml') { // For YAML/XML/TOML, save the raw markdown content with the new extension try { @@ -3025,6 +3048,7 @@ function exportToHTML(outputFile) { const marked = require('marked'); const markdownContent = fs.readFileSync(currentFile, 'utf8'); const htmlContent = marked.parse(markdownContent); + const monospaceCss = buildMonospaceExportCss(); const fullHtml = ` @@ -3032,6 +3056,7 @@ function exportToHTML(outputFile) { Exported Document