diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..93967ae --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,24 @@ +{ + "permissions": { + "allow": [ + "Bash(git checkout:*)", + "Bash(npm install)", + "Bash(npm run build:*)", + "Bash(rmdir:*)", + "Bash(powershell:*)", + "Bash(npx electron-builder:*)", + "Bash(dir dist)", + "Bash(git tag:*)", + "Bash(git push:*)", + "Bash(gh release create:*)", + "Bash(gh auth:*)", + "Bash(gh release delete:*)", + "Bash(gh release list:*)", + "Bash(gh release upload:*)", + "Bash(npm install:*)", + "Bash(npm uninstall:*)", + "Bash(git add:*)" + ], + "deny": [] + } +} \ No newline at end of file diff --git a/package.json b/package.json index 802754b..c8fa45b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pan-converter", - "version": "1.3.4", + "version": "1.3.6", "description": "Cross-platform Markdown editor and converter using Pandoc", "main": "src/main.js", "scripts": { @@ -33,6 +33,7 @@ "electron-store": "^10.1.0", "highlight.js": "^11.11.1", "marked": "^16.2.1", + "tslib": "^2.8.1", "xlsx": "^0.18.5" }, "build": { @@ -58,7 +59,7 @@ { "ext": "markdown", "name": "Markdown Document", - "description": "Markdown Document", + "description": "Markdown Document", "mimeType": "text/markdown", "role": "Editor" } diff --git a/src/main.js b/src/main.js index c3fb7b0..cc35f61 100644 --- a/src/main.js +++ b/src/main.js @@ -192,7 +192,7 @@ function createMenu() { type: 'info', title: 'About PanConverter', message: 'PanConverter', - detail: 'A cross-platform Markdown editor and converter using Pandoc.\n\nVersion: 1.3.4\nAuthor: Amit Haridas\nEmail: amit.wh@gmail.com\nLicense: MIT\n\nFeatures:\n• Tabbed interface for multiple files\n• Advanced markdown editing with live preview\n• Enhanced PDF export with LaTeX engines\n• File association support for .md files\n• Improved preview typography and spacing\n• Adjustable font sizes via menu (Ctrl+Shift+Plus/Minus)\n• Complete theme support including Monokai fixes\n• Find & replace with match highlighting\n• Line numbers and auto-indentation\n• Export to multiple formats via Pandoc\n• PowerPoint & presentation export\n• Export tables to Excel/ODS spreadsheets\n• Document import & conversion\n• Table creation helper\n• Multiple themes support\n• Undo/redo functionality', + detail: 'A cross-platform Markdown editor and converter using Pandoc.\n\nVersion: 1.3.6\nAuthor: Amit Haridas\nEmail: amit.wh@gmail.com\nLicense: MIT\n\nFeatures:\n• Tabbed interface for multiple files\n• Advanced markdown editing with live preview\n• Enhanced PDF export with built-in Electron fallback\n• File association support for .md files\n• Improved preview typography and spacing\n• Adjustable font sizes via menu (Ctrl+Shift+Plus/Minus)\n• Complete theme support including Monokai fixes\n• Find & replace with match highlighting\n• Line numbers and auto-indentation\n• Export to multiple formats via Pandoc\n• PowerPoint & presentation export\n• Export tables to Excel/ODS spreadsheets\n• Document import & conversion\n• Table creation helper\n• Multiple themes support\n• Undo/redo functionality', buttons: ['OK'] }); } @@ -268,15 +268,126 @@ function exportFile(format) { if (fallbackError) { // Final fallback to wkhtmltopdf const htmlToPdfCmd = `pandoc "${currentFile}" -t html5 | wkhtmltopdf - "${outputFile}"`; - exec(htmlToPdfCmd, (finalError) => { + exec(htmlToPdfCmd, async (finalError) => { if (finalError) { - dialog.showErrorBox('PDF Export Error', - `Failed to export PDF. Please ensure you have one of the following installed:\n` + - `• XeLaTeX (recommended): sudo apt-get install texlive-xetex\n` + - `• PDFLaTeX: sudo apt-get install texlive-latex-base\n` + - `• wkhtmltopdf: sudo apt-get install wkhtmltopdf\n\n` + - `Error: ${finalError.message}` - ); + // Ultimate fallback: Use Electron's built-in PDF export + try { + const marked = require('marked'); + const fs = require('fs'); + + // Read markdown file + const markdownContent = fs.readFileSync(currentFile, 'utf8'); + + // Convert markdown to HTML + const htmlContent = marked.parse(markdownContent); + + // Create full HTML document with styling + const fullHtml = ` + + +
+ + + + + ${htmlContent} + + + `; + + // Create a hidden window to render and export PDF + const { BrowserWindow } = require('electron'); + const pdfWindow = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: true, + contextIsolation: false + } + }); + + await pdfWindow.loadURL(`data:text/html;charset=utf-8,${encodeURIComponent(fullHtml)}`); + + const pdfData = await pdfWindow.webContents.printToPDF({ + marginsType: 1, // Use default margins + pageSize: 'A4', + printBackground: true, + printSelectionOnly: false, + landscape: false + }); + + fs.writeFileSync(outputFile, pdfData); + pdfWindow.close(); + + showExportSuccess(outputFile); + } catch (electronPdfError) { + dialog.showErrorBox('PDF Export Error', + `Failed to export PDF. The built-in PDF export encountered an error.\n\n` + + `For better PDF export, please install one of the following:\n` + + `• XeLaTeX (recommended)\n` + + `• PDFLaTeX\n` + + `• wkhtmltopdf\n\n` + + `Error: ${electronPdfError.message}` + ); + } } else { showExportSuccess(outputFile); }