Skip to content

Commit d724281

Browse files
committed
feat(new tool): HTML to Markdown (with paste)
Convert HTML to Markdown, allow pasting from clipboard (ie, pasting part of a web page or copy paste from Word) Fix partially CorentinTh#538. Inspired by CorentinTh#632 Using turndown
1 parent 5641816 commit d724281

File tree

5 files changed

+73
-6
lines changed

5 files changed

+73
-6
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@tiptap/pm": "2.1.6",
4242
"@tiptap/starter-kit": "2.1.6",
4343
"@tiptap/vue-3": "2.0.3",
44+
"@types/turndown": "^5.0.4",
4445
"@vicons/material": "^0.12.0",
4546
"@vicons/tabler": "^0.12.0",
4647
"@vueuse/core": "^10.3.0",
@@ -79,6 +80,7 @@
7980
"plausible-tracker": "^0.3.8",
8081
"qrcode": "^1.5.1",
8182
"sql-formatter": "^13.0.0",
83+
"turndown": "^7.1.2",
8284
"ua-parser-js": "^1.0.35",
8385
"ulid": "^2.3.0",
8486
"unicode-emoji-json": "^0.4.0",

pnpm-lock.yaml

Lines changed: 26 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script setup lang="ts">
2+
import TurndownService from 'turndown';
3+
import TextareaCopyable from '@/components/TextareaCopyable.vue';
4+
5+
const turndownService = new TurndownService();
6+
7+
const inputHtml = ref('');
8+
const outputMarkdown = computed(() => {
9+
return turndownService.turndown(inputHtml.value ?? '');
10+
});
11+
</script>
12+
13+
<template>
14+
<div>
15+
<c-input-text
16+
v-model:value="inputHtml"
17+
multiline raw-text
18+
placeholder="Your Html content..."
19+
rows="8"
20+
autofocus
21+
label="Your Html to convert (can paste from clipboard):"
22+
paste-html
23+
/>
24+
25+
<n-divider />
26+
27+
<n-form-item label="Output markdown:">
28+
<TextareaCopyable :value="outputMarkdown" />
29+
</n-form-item>
30+
</div>
31+
</template>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Markdown } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Html to markdown',
6+
path: '/html-to-markdown',
7+
description: 'Convert HTML (either from clipboard) to Markdown',
8+
keywords: ['html', 'markdown', 'converter'],
9+
component: () => import('./html-to-markdown.vue'),
10+
icon: Markdown,
11+
createdAt: new Date('2024-01-17'),
12+
});

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import { tool as uuidGenerator } from './uuid-generator';
7777
import { tool as macAddressLookup } from './mac-address-lookup';
7878
import { tool as xmlFormatter } from './xml-formatter';
7979
import { tool as yamlViewer } from './yaml-viewer';
80+
import { tool as htmlToMarkdown } from './html-to-markdown';
8081

8182
export const toolsByCategory: ToolCategory[] = [
8283
{
@@ -103,6 +104,7 @@ export const toolsByCategory: ToolCategory[] = [
103104
listConverter,
104105
tomlToJson,
105106
tomlToYaml,
107+
htmlToMarkdown,
106108
],
107109
},
108110
{

0 commit comments

Comments
 (0)