feat(new tools): HTML/Markdown to data

Fix #416
This commit is contained in:
ShareVB committed 2026-07-05 12:45:09 +02:00
1 parent be6a951e43
commit 2a4fcc6e4d
7 files changed
+331 -32

No files matched your search

+41 -32
View File
@@ -122,39 +122,39 @@ home:
it-tools-handy-online-tools-for-developers: IT Tools - Handy online tools for developers
tools:
crop-image:
title: "Crop image"
description: "Crop, resize, and rotate images with custom background colors."
title: Crop image
description: Crop, resize, and rotate images with custom background colors.
texts:
drag-drop: "Drag and drop your image here, or click to browse"
drag-hint: "Drag to position • Scroll to zoom ({zoom}%)"
flip-h: "Flip H"
flip-v: "Flip V"
reset: "Reset"
fit: "Fit"
change-image: "Change Image"
aspect-ratio: "Aspect Ratio:"
custom-ratio: "Custom Ratio:"
background-color: "Background Color:"
transparent: "Transparent"
zoom-image: "Zoom Image:"
rotate-image: "Rotate Image:"
rule-of-thirds-grid: "Rule-of-Thirds Grid:"
export-settings: "Export Settings"
export-format: "Export Format:"
image-quality: "Image Quality:"
export-width: "Export Width:"
custom-width: "Custom Width (px):"
export-download-image: "Export & Download Cropped Image"
ratio-square: "1:1 (Square)"
ratio-widescreen: "16:9 (Widescreen)"
ratio-portrait: "9:16 (Portrait)"
ratio-standard: "4:3 (Standard)"
ratio-photo: "3:2 (Photo)"
ratio-original: "Original Aspect Ratio"
ratio-custom: "Custom Ratio"
width-original: "Original Crop Size"
width-viewport: "Viewport Size"
width-custom: "Custom Width"
drag-drop: Drag and drop your image here, or click to browse
drag-hint: Drag to position • Scroll to zoom ({zoom}%)
flip-h: Flip H
flip-v: Flip V
reset: Reset
fit: Fit
change-image: Change Image
aspect-ratio: 'Aspect Ratio:'
custom-ratio: 'Custom Ratio:'
background-color: 'Background Color:'
transparent: Transparent
zoom-image: 'Zoom Image:'
rotate-image: 'Rotate Image:'
rule-of-thirds-grid: 'Rule-of-Thirds Grid:'
export-settings: Export Settings
export-format: 'Export Format:'
image-quality: 'Image Quality:'
export-width: 'Export Width:'
custom-width: 'Custom Width (px):'
export-download-image: Export & Download Cropped Image
ratio-square: 1:1 (Square)
ratio-widescreen: 16:9 (Widescreen)
ratio-portrait: 9:16 (Portrait)
ratio-standard: 4:3 (Standard)
ratio-photo: 3:2 (Photo)
ratio-original: Original Aspect Ratio
ratio-custom: Custom Ratio
width-original: Original Crop Size
width-viewport: Viewport Size
width-custom: Custom Width
chronometer:
title: Chronometer
description: >-
@@ -8855,6 +8855,15 @@ tools:
tag-copy: Copy
tag-refresh: Refresh
text-picked-lines-copied-to-clipboard: Picked lines copied to clipboard!
markdown-to-data:
texts:
label-paste-your-markdown-content: 'Paste your markdown content:'
placeholder-your-markdown: Your markdown...
html-to-data:
texts:
label-paste-your-html-content: 'Paste your HTML content:'
placeholder-your-html: Your HTML here...
error-multiple-json-blocks: Cannot convert multiple tables at once
collapsibleToolMenu:
text:
expanding: Expanding...
+2
View File
@@ -262,6 +262,7 @@
"marked": "^10.0.0",
"mathjs": "^15.2.0",
"md-editor-v3": "^4.21.3",
"mdt2json": "^1.1.0",
"memorystream": "^0.3.1",
"merge-anything": "^6.0.6",
"mermaid": "^11.12.2",
@@ -426,6 +427,7 @@
"@types/text-encoding-utf-8": "^1.0.5",
"@types/turndown": "^5.0.6",
"@types/ua-parser-js": "^0.7.39",
"@types/unist": "^3.0.3",
"@types/utf8": "^3.0.3",
"@types/uuid": "^10.0.0",
"@unocss/eslint-config": "^0.57.1",
+12
View File
@@ -683,6 +683,9 @@ importers:
md-editor-v3:
specifier: ^4.21.3
version: 4.21.3(vue@3.3.4)
mdt2json:
specifier: ^1.1.0
version: 1.1.0
memorystream:
specifier: ^0.3.1
version: 0.3.1
@@ -1170,6 +1173,9 @@ importers:
'@types/ua-parser-js':
specifier: ^0.7.39
version: 0.7.39
'@types/unist':
specifier: ^3.0.3
version: 3.0.3
'@types/utf8':
specifier: ^3.0.3
version: 3.0.3
@@ -8836,6 +8842,10 @@ packages:
mdn-data@2.0.30:
resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==}
mdt2json@1.1.0:
resolution: {integrity: sha512-YlZ7xP25OgiGKYC/DYk+XqhKTnSHF7M/74A3I76AjNqrVfmCMuQN8sOzfLI2aCo189Kb17gqJk/UhYg2iKi1WA==}
hasBin: true
mdurl@2.0.0:
resolution: {integrity: sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==}
@@ -20746,6 +20756,8 @@ snapshots:
mdn-data@2.0.30: {}
mdt2json@1.1.0: {}
mdurl@2.0.0: {}
medium-zoom@1.1.0: {}
+137
View File
@@ -0,0 +1,137 @@
<script lang="ts" setup>
import { useI18n } from 'vue-i18n';
import * as XLSX from 'xlsx';
import TurndownService from 'turndown';
import { JsonLayout, MarkdownTable2Json } from 'mdt2json';
import { gfm as addGFM } from '@guyplusplus/turndown-plugin-gfm';
import { objectArrayToData } from '@/utils/objectarray.export';
import type { ExportFormat } from '@/utils/objectarray.export';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const { t } = useI18n();
const htmlContent = ref('');
const error = ref('');
const convertedData = ref<string>('');
const selectedFormat = useQueryParamOrStorage({ name: 'fmt', storageName: 'html-to-data:fmt', defaultValue: 'json' });
const tableName = useQueryParamOrStorage({ name: 'table', storageName: 'html-to-data:tbl', defaultValue: 'TableName' });
const nestify = ref(false);
const typedValues = ref(false);
const formats = [
{ label: t('tools.csv-to-data.texts.label-json'), value: 'json' },
{ label: t('tools.csv-to-data.texts.label-yaml'), value: 'yaml' },
{ label: t('tools.csv-to-data.texts.label-sql-insert'), value: 'sql' },
{ label: t('tools.csv-to-data.texts.label-csv-comma'), value: 'csv' },
{ label: t('tools.csv-to-data.texts.label-csv-semicolon'), value: 'csv_semicolon' },
{ label: t('tools.csv-to-data.texts.label-csv-tab'), value: 'tsv' },
{ label: t('tools.csv-to-data.texts.label-markdown'), value: 'markdown' },
{ label: t('tools.csv-to-data.texts.label-xml'), value: 'xml' },
{ label: t('tools.csv-to-data.texts.label-xlsx'), value: 'xlsx' },
];
const turndownService = new TurndownService();
function escapeMarkdown(text: string) {
return text
.replace(/\\/g, '\\\\') // escape backslash first
.replace(/([*_#>|`])/g, '\\$1') // escape common markdown symbols
.replace(/([\[\]\(\)])/g, '\\$1') // escape brackets and parentheses
.replace(/\|/g, '\\|'); // escape table pipes
}
turndownService.addRule('escapeText', {
filter(node) {
return node.nodeType === 3; // text nodes
},
replacement(content) {
return escapeMarkdown(content);
},
});
addGFM(turndownService);
async function convertContent() {
const htmlContentValue = htmlContent.value;
error.value = '';
convertedData.value = '';
try {
const markdownContent = turndownService.turndown(htmlContentValue);
const transpiler = new MarkdownTable2Json({ markdownString: markdownContent, layout: JsonLayout.AoS, minify: true });
const output_markdown = transpiler.transform();
if ([...output_markdown?.match(/```json/g) || []].length > 1) {
throw new Error(t('tools.html-to-data.texts.error-multiple-json-blocks'));
}
const output_first_codeblock = output_markdown?.match(/```json\n(.*?)\n```/s)?.[1] || '[]';
const data = JSON.parse(output_first_codeblock);
const outFormat = selectedFormat.value;
if (outFormat === 'xlsx') {
convertedData.value = '';
downloadXLSX(data, tableName.value);
}
else {
convertedData.value = objectArrayToData(data, outFormat as ExportFormat, {
tableName: tableName.value,
nestify: nestify.value,
});
}
}
catch (e: any) {
error.value = e.toString();
return null;
}
};
function downloadXLSX<T extends Record<string, any>>(data: T[], fileName: string = 'data') {
const worksheet = XLSX.utils.json_to_sheet(data);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, fileName);
XLSX.writeFile(workbook, `${fileName}.xlsx`);
}
</script>
<template>
<div>
<c-input-text
v-model:value="htmlContent"
:label="t('tools.html-to-data.texts.label-paste-your-html-content')"
:placeholder="t('tools.html-to-data.texts.placeholder-your-html')"
multiline
paste-html
rows="8"
/>
<n-space justify="center">
<n-form-item :label="t('tools.csv-to-data.texts.label-typed-values')" label-placement="left">
<n-checkbox v-model:checked="typedValues" />
</n-form-item>
<n-form-item :label="t('tools.csv-to-data.texts.label-nestify-a-b-c-to-nested-objects')" label-placement="left">
<n-checkbox v-model:checked="nestify" />
</n-form-item>
</n-space>
<NFormItem :label="t('tools.csv-to-data.texts.label-select-output-format')" label-placement="left">
<NSelect v-model:value="selectedFormat" :options="formats" :placeholder="t('tools.csv-to-data.texts.placeholder-select-format')" />
</NFormItem>
<c-input-text v-if="selectedFormat === 'sql'" v-model:value="tableName" :label="t('tools.csv-to-data.texts.label-table-name')" label-placement="left" />
<div mt-3 flex justify-center>
<NButton :disabled="!htmlContent" @click="convertContent">
{{ t('tools.csv-to-data.texts.tag-convert') }}
</NButton>
</div>
<c-alert v-if="error" mt-2>
{{ error }}
</c-alert>
<c-card v-if="convertedData" :title="t('tools.csv-to-data.texts.title-converted-data')">
<textarea-copyable :value="convertedData" :language="selectedFormat" :download-file-name="`output.${selectedFormat}`" />
</c-card>
</div>
</template>
+13
View File
@@ -0,0 +1,13 @@
import { TableExport } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'HTML to data',
path: '/html-to-data',
description: 'Convert HTML table to JSON, YAML, CSV, SQL INSERT, XML, Markdown or XLSX',
keywords: ['html', 'table', 'excel', 'csv', 'xlsx', 'sql', 'json', 'yaml', 'insert', 'markdown', 'md', 'tsv', 'xml'],
component: () => import('./html-to-data.vue'),
icon: TableExport,
createdAt: new Date('2026-07-04'),
category: 'Web',
});
+13
View File
@@ -0,0 +1,13 @@
import { TableExport } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Markdown to data',
path: '/markdown-to-data',
description: 'Convert Markdown table to JSON, YAML, CSV, SQL INSERT, XML, Markdown or XLSX',
keywords: ['markdown', 'table', 'excel', 'csv', 'xlsx', 'sql', 'json', 'yaml', 'insert', 'md', 'tsv', 'xml'],
component: () => import('./markdown-to-data.vue'),
icon: TableExport,
createdAt: new Date('2026-07-04'),
category: 'Markdown',
});
@@ -0,0 +1,113 @@
<script lang="ts" setup>
import { useI18n } from 'vue-i18n';
import * as XLSX from 'xlsx';
import { JsonLayout, MarkdownTable2Json } from 'mdt2json';
import { objectArrayToData } from '@/utils/objectarray.export';
import type { ExportFormat } from '@/utils/objectarray.export';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const { t } = useI18n();
const mdContent = ref('');
const error = ref('');
const convertedData = ref<string>('');
const selectedFormat = useQueryParamOrStorage({ name: 'fmt', storageName: 'md-to-data:fmt', defaultValue: 'json' });
const tableName = useQueryParamOrStorage({ name: 'table', storageName: 'md-to-data:tbl', defaultValue: 'TableName' });
const nestify = ref(false);
const typedValues = ref(false);
const formats = [
{ label: t('tools.csv-to-data.texts.label-json'), value: 'json' },
{ label: t('tools.csv-to-data.texts.label-yaml'), value: 'yaml' },
{ label: t('tools.csv-to-data.texts.label-sql-insert'), value: 'sql' },
{ label: t('tools.csv-to-data.texts.label-csv-comma'), value: 'csv' },
{ label: t('tools.csv-to-data.texts.label-csv-semicolon'), value: 'csv_semicolon' },
{ label: t('tools.csv-to-data.texts.label-csv-tab'), value: 'tsv' },
{ label: t('tools.csv-to-data.texts.label-markdown'), value: 'markdown' },
{ label: t('tools.csv-to-data.texts.label-xml'), value: 'xml' },
{ label: t('tools.csv-to-data.texts.label-xlsx'), value: 'xlsx' },
];
async function convertContent() {
const mdContentValue = mdContent.value;
error.value = '';
convertedData.value = '';
try {
const transpiler = new MarkdownTable2Json({ markdownString: mdContentValue, layout: JsonLayout.AoS, minify: true });
const output_markdown = transpiler.transform();
if ([...output_markdown?.match(/```json/g) || []].length > 1) {
throw new Error(t('tools.html-to-data.texts.error-multiple-json-blocks'));
}
const output_first_codeblock = output_markdown?.match(/```json\n(.*?)\n```/s)?.[1] || '[]';
const data = JSON.parse(output_first_codeblock);
const outFormat = selectedFormat.value;
if (outFormat === 'xlsx') {
convertedData.value = '';
downloadXLSX(data, tableName.value);
}
else {
convertedData.value = objectArrayToData(data, outFormat as ExportFormat, {
tableName: tableName.value,
nestify: nestify.value,
});
}
}
catch (e: any) {
error.value = e.toString();
return null;
}
};
function downloadXLSX<T extends Record<string, any>>(data: T[], fileName: string = 'data') {
const worksheet = XLSX.utils.json_to_sheet(data);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, fileName);
XLSX.writeFile(workbook, `${fileName}.xlsx`);
}
</script>
<template>
<div>
<c-input-text
v-model:value="mdContent"
:label="t('tools.markdown-to-data.texts.label-paste-your-markdown-content')"
:placeholder="t('tools.markdown-to-data.texts.placeholder-your-markdown')"
multiline
rows="8"
/>
<n-space justify="center">
<n-form-item :label="t('tools.csv-to-data.texts.label-typed-values')" label-placement="left">
<n-checkbox v-model:checked="typedValues" />
</n-form-item>
<n-form-item :label="t('tools.csv-to-data.texts.label-nestify-a-b-c-to-nested-objects')" label-placement="left">
<n-checkbox v-model:checked="nestify" />
</n-form-item>
</n-space>
<NFormItem :label="t('tools.csv-to-data.texts.label-select-output-format')" label-placement="left">
<NSelect v-model:value="selectedFormat" :options="formats" :placeholder="t('tools.csv-to-data.texts.placeholder-select-format')" />
</NFormItem>
<c-input-text v-if="selectedFormat === 'sql'" v-model:value="tableName" :label="t('tools.csv-to-data.texts.label-table-name')" label-placement="left" />
<div mt-3 flex justify-center>
<NButton :disabled="!mdContent" @click="convertContent">
{{ t('tools.csv-to-data.texts.tag-convert') }}
</NButton>
</div>
<c-alert v-if="error" mt-2>
{{ error }}
</c-alert>
<c-card v-if="convertedData" :title="t('tools.csv-to-data.texts.title-converted-data')">
<textarea-copyable :value="convertedData" :language="selectedFormat" :download-file-name="`output.${selectedFormat}`" />
</c-card>
</div>
</template>