Skip to content

Commit 95722a6

Browse files
committed
feat: add print button
1 parent 916a6fb commit 95722a6

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ declare module '@vue/runtime-core' {
128128
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
129129
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
130130
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
131+
NButton: typeof import('naive-ui')['NButton']
131132
NCode: typeof import('naive-ui')['NCode']
132133
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
133134
NConfigProvider: typeof import('naive-ui')['NConfigProvider']

src/tools/markdown-to-html/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Markdown } from '@vicons/tabler';
22
import { defineTool } from '../tool';
33

44
export const tool = defineTool({
5-
name: 'Markdown to html',
5+
name: 'Markdown to Html',
66
path: '/markdown-to-html',
7-
description: '',
8-
keywords: ['markdown', 'html', 'converter'],
7+
description: 'Convert Markdown to Html and allow to print (as PDF)',
8+
keywords: ['markdown', 'html', 'converter', 'pdf'],
99
component: () => import('./markdown-to-html.vue'),
1010
icon: Markdown,
11-
createdAt: new Date('2024-02-25'),
11+
createdAt: new Date('2024-08-15'),
1212
});

src/tools/markdown-to-html/markdown-to-html.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ const outputHtml = computed(() => {
77
const md = markdownit();
88
return md.render(inputMarkdown.value);
99
});
10+
11+
function printHtml() {
12+
const w = window.open();
13+
if (w === null) {
14+
return;
15+
}
16+
w.document.body.innerHTML = outputHtml.value;
17+
w.print();
18+
}
1019
</script>
1120

1221
<template>
@@ -25,5 +34,11 @@ const outputHtml = computed(() => {
2534
<n-form-item label="Output HTML:">
2635
<TextareaCopyable :value="outputHtml" :word-wrap="true" language="html" />
2736
</n-form-item>
37+
38+
<div flex justify-center>
39+
<n-button @click="printHtml">
40+
Print (ie, use a PDF Printer to get a PDF file)
41+
</n-button>
42+
</div>
2843
</div>
2944
</template>

0 commit comments

Comments
 (0)