diff --git a/src/main/index.ts b/src/main/index.ts index 457c765..2aa2a84 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -3,16 +3,16 @@ import { join } from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' import icon from '../../resources/icon.png?asset' import fs from 'node:fs/promises' -import { readFileSync } from 'node:fs' import path from 'node:path' import { mdToHtml } from '../../lib/render' import { getTheme } from '../../lib/theme' +import { embedImageIntoHtml } from './utils' function createWindow(): void { // Create the browser window. const mainWindow = new BrowserWindow({ width: 905, - height: 670, + height: 700, minWidth: 768, minHeight: 512, show: false, @@ -120,21 +120,9 @@ app.whenReady().then(() => { } } ) - ipcMain.handle( - 'embedImageIntoHtml', - async (_, html: string, filepath: string): Promise => { - return html.replace(/ { - if (p1.startsWith('http')) return match - try { - const url = path.resolve(filepath, decodeURI(p1)) - const data = readFileSync(url).toString('base64') - return ` => { + return embedImageIntoHtml(html, filepath) + }) ipcMain.handle( 'createPdf', async ( @@ -156,16 +144,7 @@ app.whenReady().then(() => { } const theme = getTheme(themeName) const dist = path.resolve(filePath) - const html = (await mdToHtml(markdown, theme)).replace(/ { - if (p1.startsWith('http')) return match - try { - const url = path.resolve(filepath, decodeURI(p1)) - const data = readFileSync(url).toString('base64') - return ` { + return html.replace(/ { + if (p1.startsWith('http')) return match + try { + const url = path.resolve(filepath, decodeURI(p1)) + const data = readFileSync(url).toString('base64') + return ` 新建 @@ -47,16 +50,21 @@ export default function Toolbar(): JSX.Element { setFilename(filename) setFilepath(filepath) setMarkdown(content) + setSavedMarkdown(content) }} > 打开