feat(Markdown to Html): more options (html, sub, sup, mark, align)

Add options to allow html tags, to sanitize html tags
To support Superscript (^), Subscript (~), Mark (==)
And alignment ::: center ... :::
This commit is contained in:
ShareVB committed 2025-03-02 21:59:51 +01:00
1 parent 31d2426614
commit 415659f6b6
4 files changed
+117 -4

No files matched your search

+5
View File
@@ -47,6 +47,7 @@
"@it-tools/oggen": "^1.3.0",
"@kenjiuno/decompressrtf": "^0.1.4",
"@kenjiuno/msgreader": "^1.22.0",
"@mdit/plugin-align": "^0.16.0",
"@regexper/render": "^1.0.0",
"@sindresorhus/slugify": "^2.2.1",
"@tabler/icons-vue": "^3.20.0",
@@ -175,6 +176,10 @@
"luhn-js": "^1.1.2",
"luxon": "^3.5.0",
"markdown-it": "^14.1.0",
"markdown-it-mark": "^4.0.0",
"markdown-it-sanitizer": "^0.4.3",
"markdown-it-sub": "^2.0.0",
"markdown-it-sup": "^2.0.0",
"marked": "^10.0.0",
"mathjs": "^14.2.1",
"md-editor-v3": "^4.21.3",
+53 -3
View File
@@ -35,6 +35,9 @@ dependencies:
'@kenjiuno/msgreader':
specifier: ^1.22.0
version: 1.22.0
'@mdit/plugin-align':
specifier: ^0.16.0
version: 0.16.0(markdown-it@14.1.0)
'@regexper/render':
specifier: ^1.0.0
version: 1.0.0
@@ -419,6 +422,18 @@ dependencies:
markdown-it:
specifier: ^14.1.0
version: 14.1.0
markdown-it-mark:
specifier: ^4.0.0
version: 4.0.0
markdown-it-sanitizer:
specifier: ^0.4.3
version: 0.4.3
markdown-it-sub:
specifier: ^2.0.0
version: 2.0.0
markdown-it-sup:
specifier: ^2.0.0
version: 2.0.0
marked:
specifier: ^10.0.0
version: 10.0.0
@@ -4660,6 +4675,33 @@ packages:
resolution: {integrity: sha512-mrC4y8n88BYvgcgzq9bvTlDgFyi2zuvzmPilRvRc3Uz1iIvq8mDhxJ0rHKFUNzPEScpDvJdIujqiDrulMqiudA==}
dev: true
/@mdit/plugin-align@0.16.0(markdown-it@14.1.0):
resolution: {integrity: sha512-BJhOjX4Zobs+ZKEpDtxGrUCnppkFCTGIBLjXkCPmxeLf4Tsh7dqv5vVhbRueSOz/EIzc2RJzR0dlMLofsaCFeA==}
engines: {node: '>= 18'}
peerDependencies:
markdown-it: ^14.1.0
peerDependenciesMeta:
markdown-it:
optional: true
dependencies:
'@mdit/plugin-container': 0.16.0(markdown-it@14.1.0)
'@types/markdown-it': 14.1.2
markdown-it: 14.1.0
dev: false
/@mdit/plugin-container@0.16.0(markdown-it@14.1.0):
resolution: {integrity: sha512-NCsyEiOmoJvXSEVJSY6vaEcvbE11sciRSx5qXBvQQZxUYGYsB+ObYSFVZDFPezsEN35X3b07rurLx8P2Mi9DgQ==}
engines: {node: '>= 18'}
peerDependencies:
markdown-it: ^14.1.0
peerDependenciesMeta:
markdown-it:
optional: true
dependencies:
'@types/markdown-it': 14.1.2
markdown-it: 14.1.0
dev: false
/@mixmark-io/domino@2.2.0:
resolution: {integrity: sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw==}
dev: false
@@ -6243,7 +6285,7 @@ packages:
dependencies:
'@unhead/dom': 0.5.1
'@unhead/schema': 0.5.1
'@vueuse/shared': 12.5.0(typescript@5.2.2)
'@vueuse/shared': 12.7.0(typescript@5.2.2)
unhead: 0.5.1
vue: 3.3.4
transitivePeerDependencies:
@@ -6946,8 +6988,8 @@ packages:
- vue
dev: false
/@vueuse/shared@12.5.0(typescript@5.2.2):
resolution: {integrity: sha512-vMpcL1lStUU6O+kdj6YdHDixh0odjPAUM15uJ9f7MY781jcYkIwFA4iv2EfoIPO6vBmvutI1HxxAwmf0cx5ISQ==}
/@vueuse/shared@12.7.0(typescript@5.2.2):
resolution: {integrity: sha512-coLlUw2HHKsm7rPN6WqHJQr18WymN4wkA/3ThFaJ4v4gWGWAQQGK+MJxLuJTBs4mojQiazlVWAKNJNpUWGRkNw==}
dependencies:
vue: 3.5.13(typescript@5.2.2)
transitivePeerDependencies:
@@ -12411,6 +12453,14 @@ packages:
markdown-it: 14.1.0
dev: false
/markdown-it-mark@4.0.0:
resolution: {integrity: sha512-YLhzaOsU9THO/cal0lUjfMjrqSMPjjyjChYM7oyj4DnyaXEzA8gnW6cVJeyCrCVeyesrY2PlEdUYJSPFYL4Nkg==}
dev: false
/markdown-it-sanitizer@0.4.3:
resolution: {integrity: sha512-0Q2ua8+oDN7/3r5UXMnbVq8C+LRfT2pzVKA+h4nXTLEMBFQDwp7qJZOe7DkBa79C7V2cSBXJyScxJ7vYs9kE2w==}
dev: false
/markdown-it-sub@2.0.0:
resolution: {integrity: sha512-iCBKgwCkfQBRg2vApy9vx1C1Tu6D8XYo8NvevI3OlwzBRmiMtsJ2sXupBgEA7PPxiDwNni3qIUkhZ6j5wofDUA==}
dev: false
+15
View File
@@ -0,0 +1,15 @@
declare module 'markdown-it-sanitizer' {
export default function Plugin(): MarkdownIt.PluginSimple;
}
declare module 'markdown-it-sup' {
export default function Plugin(): MarkdownIt.PluginSimple;
}
declare module 'markdown-it-sub' {
export default function Plugin(): MarkdownIt.PluginSimple;
}
declare module 'markdown-it-mark' {
export default function Plugin(): MarkdownIt.PluginSimple;
}
@@ -1,10 +1,33 @@
<script setup lang="ts">
import markdownit from 'markdown-it';
import markdownitSanitizer from 'markdown-it-sanitizer';
import markdownitSup from 'markdown-it-sup';
import markdownitSub from 'markdown-it-sub';
import markdownitMark from 'markdown-it-mark';
import { align } from '@mdit/plugin-align';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const handleHtml = ref(true);
const sanitize = ref(true);
const handleAlign = ref(false);
const handleSubSup = ref(false);
const handleMark = ref(false);
const inputMarkdown = ref('');
const outputHtml = computed(() => {
const md = markdownit();
let md = markdownit({ html: handleHtml.value });
if (handleHtml.value && sanitize.value) {
md = md.use(markdownitSanitizer);
}
if (handleAlign.value) {
md = md.use(align as never);
}
if (handleSubSup.value) {
md = md.use(markdownitSub).use(markdownitSup);
}
if (handleMark.value) {
md = md.use(markdownitMark);
}
return md.render(inputMarkdown.value);
});
@@ -29,6 +52,26 @@ function printHtml() {
label="Your Markdown to convert:"
/>
<n-space justify="center" gap-1>
<n-checkbox v-model:checked="handleHtml">
Allow HTML tags
</n-checkbox>
<n-checkbox v-model:checked="sanitize" :disabled="!handleHtml">
Sanitize HTML
</n-checkbox>
<n-checkbox v-model:checked="handleSubSup">
Allow Superscript (^) and Subscript (~)
</n-checkbox>
<n-checkbox v-model:checked="handleAlign">
Handle <n-a href="https://mdit-plugins.github.io/align.html#syntax" target="blank">
alignment
</n-a>
</n-checkbox>
<n-checkbox v-model:checked="handleMark">
Allow Mark (==)
</n-checkbox>
</n-space>
<n-divider />
<n-form-item label="Output HTML:">