Skip to content

Commit 2f3bada

Browse files
fix(snippets): export to html #309 (#320)
1 parent 4cf24c9 commit 2f3bada

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

src/renderer/components/editor/EditorPreview.vue

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,30 @@ const setSrcDoc = () => {
9393
}
9494
`
9595
96-
srcDoc.value = `<html>
97-
<body>${html || htmlDefault}<body>
98-
<style>${cssDefault + css}<style>
99-
</html>
96+
srcDoc.value = `<!DOCTYPE html>
97+
<html>
98+
<head>
99+
<meta charset="UTF-8">
100+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
101+
<title>${snippetStore.selected?.name}</title>
102+
</head>
103+
<body>${html || htmlDefault}</body>
104+
<style>${cssDefault + css}</style>
105+
</html>
100106
`
101107
}
108+
102109
setSrcDoc()
103110
104-
const onSaveToHtml = () => {
111+
const onSaveToHtml = async () => {
112+
const formatted = await ipc.invoke('main:prettier', {
113+
source: srcDoc.value,
114+
parser: 'html'
115+
})
116+
105117
const a = document.createElement('a')
106118
107-
a.href = `data:text/plain;charset=utf-8, ${encodeURIComponent(srcDoc.value)}`
108-
console.log(a)
119+
a.href = `data:text/plain;charset=utf-8, ${encodeURIComponent(formatted)}`
109120
a.download = `${snippetStore.selected?.name}.html`
110121
a.click()
111122
}

0 commit comments

Comments
 (0)