diff --git a/package.json b/package.json index c253f0d8..110fa393 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@github/paste-markdown": "^1.5.3", "@chenfengyuan/vue-barcode": "^2.0.2", "@guolao/vue-monaco-editor": "^1.4.1", + "@guyplusplus/turndown-plugin-gfm": "^1.0.7", "@it-tools/bip39": "^0.0.4", "@it-tools/oggen": "^1.3.0", "@regexper/render": "^1.0.0", @@ -55,6 +56,7 @@ "@types/lodash.defaultsdeep": "^4.6.9", "@types/lodash.flattendeep": "^4.4.9", "@types/lodash.last": "^3.0.9", + "@types/turndown": "^5.0.4", "@vicons/material": "^0.12.0", "@vicons/tabler": "^0.12.0", "@vueuse/core": "^10.11.1", @@ -136,6 +138,7 @@ "rtf-stream-parser": "^3.8.0", "sql-formatter": "^13.0.0", "sshpk": "^1.18.0", + "turndown": "^7.1.2", "ua-parser-js": "^1.0.35", "ulid": "^2.3.0", "unicode-emoji-json": "^0.4.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1210ffff..f75f7b03 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ dependencies: '@guolao/vue-monaco-editor': specifier: ^1.4.1 version: 1.5.4(monaco-editor@0.43.0)(vue@3.3.4) + '@guyplusplus/turndown-plugin-gfm': + specifier: ^1.0.7 + version: 1.0.7 '@it-tools/bip39': specifier: ^0.0.4 version: 0.0.4 @@ -62,6 +65,9 @@ dependencies: '@types/markdown-it': specifier: ^13.0.7 version: 13.0.9 + '@types/turndown': + specifier: ^5.0.4 + version: 5.0.5 '@vicons/material': specifier: ^0.12.0 version: 0.12.0 @@ -287,6 +293,9 @@ dependencies: sshpk: specifier: ^1.18.0 version: 1.18.0 + turndown: + specifier: ^7.1.2 + version: 7.2.0 ua-parser-js: specifier: ^1.0.35 version: 1.0.35 @@ -2376,6 +2385,12 @@ packages: vue-demi: 0.14.10(vue@3.3.4) dev: false + /@guyplusplus/turndown-plugin-gfm@1.0.7: + resolution: {integrity: sha512-k2KATk491JIeq1KNsjOwaD88cdknQeTpKVXh9OuZfHdjFuSEtEVVDCfCbxzmRvJxeKDPbZQl8DGP5o7SaIvWBw==} + dependencies: + turndown: 7.2.0 + dev: false + /@humanwhocodes/config-array@0.11.10: resolution: {integrity: sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==} engines: {node: '>=10.10.0'} @@ -2682,6 +2697,10 @@ packages: resolution: {integrity: sha512-mrC4y8n88BYvgcgzq9bvTlDgFyi2zuvzmPilRvRc3Uz1iIvq8mDhxJ0rHKFUNzPEScpDvJdIujqiDrulMqiudA==} dev: true + /@mixmark-io/domino@2.2.0: + resolution: {integrity: sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw==} + dev: false + /@monaco-editor/loader@1.4.0(monaco-editor@0.43.0): resolution: {integrity: sha512-00ioBig0x642hytVspPl7DbQyaSWRaolYie/UFNjoTdvoKPzo6xrXLhTk9ixgIKcLH5b5vDOjVNiGyY+uDCUlg==} peerDependencies: @@ -3469,7 +3488,7 @@ packages: /@types/lodash-es@4.17.10: resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==} dependencies: - '@types/lodash': 4.14.200 + '@types/lodash': 4.14.192 dev: false /@types/lodash.defaultsdeep@4.6.9: @@ -3492,7 +3511,6 @@ packages: /@types/lodash@4.14.192: resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==} - dev: true /@types/lodash@4.14.200: resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==} @@ -3614,6 +3632,10 @@ packages: resolution: {integrity: sha512-NfQ4gyz38SL8sDNrSixxU2Os1a5xcdFxipAFxYEuLUlvU2uDwS4NUpsImcf1//SlWItCVMMLiylsxbmNMToV/g==} dev: true + /@types/turndown@5.0.5: + resolution: {integrity: sha512-TL2IgGgc7B5j78rIccBtlYAnkuv8nUQqhQc+DSYV5j9Be9XOcm/SKOVRuA47xAVI3680Tk9B1d8flK2GWT2+4w==} + dev: false + /@types/ua-parser-js@0.7.36: resolution: {integrity: sha512-N1rW+njavs70y2cApeIw1vLMYXRwfBy+7trgavGuuTfOd7j1Yh7QTRc/yqsPl6ncokt72ZXuxEU0PiCp9bSwNQ==} dev: true @@ -4548,7 +4570,7 @@ packages: /@vueuse/shared@10.0.0(vue@3.3.4): resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==} dependencies: - vue-demi: 0.14.10(vue@3.3.4) + vue-demi: 0.14.5(vue@3.3.4) transitivePeerDependencies: - '@vue/composition-api' - vue @@ -10418,6 +10440,12 @@ packages: resolution: {integrity: sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw==} dev: true + /turndown@7.2.0: + resolution: {integrity: sha512-eCZGBN4nNNqM9Owkv9HAtWRYfLA4h909E/WGAWWBpmB275ehNhZyk87/Tpvjbp0jjNl9XwCsbe6bm6CqFsgD+A==} + dependencies: + '@mixmark-io/domino': 2.2.0 + dev: false + /tweetnacl@0.14.5: resolution: {integrity: sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==} dev: false diff --git a/src/tools/html-to-markdown/html-to-markdown.vue b/src/tools/html-to-markdown/html-to-markdown.vue new file mode 100644 index 00000000..79fe7a33 --- /dev/null +++ b/src/tools/html-to-markdown/html-to-markdown.vue @@ -0,0 +1,38 @@ + + + diff --git a/src/tools/html-to-markdown/index.ts b/src/tools/html-to-markdown/index.ts new file mode 100644 index 00000000..5358b281 --- /dev/null +++ b/src/tools/html-to-markdown/index.ts @@ -0,0 +1,12 @@ +import { Markdown } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'Html to markdown', + path: '/html-to-markdown', + description: 'Convert HTML (either from clipboard) to Markdown', + keywords: ['html', 'markdown', 'converter'], + component: () => import('./html-to-markdown.vue'), + icon: Markdown, + createdAt: new Date('2024-01-17'), +}); diff --git a/src/tools/html-to-markdown/turndown-plugin-gfm.d.ts b/src/tools/html-to-markdown/turndown-plugin-gfm.d.ts new file mode 100644 index 00000000..0cb88c54 --- /dev/null +++ b/src/tools/html-to-markdown/turndown-plugin-gfm.d.ts @@ -0,0 +1,3 @@ +declare module '@guyplusplus/turndown-plugin-gfm' { + export function gfm(turndown: any); +} \ No newline at end of file diff --git a/src/tools/index.ts b/src/tools/index.ts index 445be7b5..4e1b049d 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -116,6 +116,7 @@ import { tool as dockerComposeToDockerRunConverter } from './docker-compose-to-d import { tool as yamlViewer } from './yaml-viewer'; import { tool as barcodeReader } from './barcode-reader'; import { tool as barcodeGenerator } from './barcode-generator'; +import { tool as htmlToMarkdown } from './html-to-markdown'; export const toolsByCategory: ToolCategory[] = [ { @@ -158,6 +159,7 @@ export const toolsByCategory: ToolCategory[] = [ listConverter, tomlToJson, tomlToYaml, + htmlToMarkdown, xmlToJson, jsonToXml, markdownToHtml, diff --git a/src/ui/c-input-text/c-input-text.vue b/src/ui/c-input-text/c-input-text.vue index c49fbf53..bd6e24b0 100644 --- a/src/ui/c-input-text/c-input-text.vue +++ b/src/ui/c-input-text/c-input-text.vue @@ -31,6 +31,7 @@ const props = withDefaults( autosize?: boolean autofocus?: boolean monospace?: boolean + pasteHtml?: boolean }>(), { value: '', @@ -58,13 +59,14 @@ const props = withDefaults( autosize: false, autofocus: false, monospace: false, + pasteHtml: false, }, ); const emit = defineEmits(['update:value']); const value = useVModel(props, 'value', emit); const showPassword = ref(false); -const { id, placeholder, label, validationRules, labelPosition, labelWidth, labelAlign, autosize, readonly, disabled, clearable, type, multiline, rows, rawText, autofocus, monospace } = toRefs(props); +const { id, placeholder, label, validationRules, labelPosition, labelWidth, labelAlign, autosize, readonly, disabled, clearable, type, multiline, rows, rawText, autofocus, monospace, pasteHtml } = toRefs(props); const validation = props.validation @@ -81,6 +83,28 @@ const textareaRef = ref(); const inputRef = ref(); const inputWrapperRef = ref(); +interface HTMLElementWithValue { + value?: string +} + +function onPasteInputHtml(evt: ClipboardEvent) { + if (!pasteHtml.value) { + return false; + } + + const target = (evt.target as HTMLElementWithValue); + if (!target) { + return false; + } + evt.preventDefault(); + const textHtmlData = evt.clipboardData?.getData('text/html'); + if (textHtmlData && textHtmlData !== '') { + value.value = textHtmlData; + return true; + } + return false; +} + watch( [value, autosize, multiline, inputWrapperRef, textareaRef], () => nextTick(() => { @@ -173,6 +197,7 @@ defineExpose({ :autocorrect="autocorrect ?? (rawText ? 'off' : undefined)" :spellcheck="spellcheck ?? (rawText ? false : undefined)" :rows="rows" + @paste="onPasteInputHtml" />