feat(new tool): html cleaner

HTML Cleaner (with paste html)
Fix #537
This commit is contained in:
sharevb 2024-04-03 22:51:05 +02:00 committed by ShareVB
parent d3b32cc14e
commit c0c5cfda87
5 changed files with 257 additions and 16 deletions

View file

@ -0,0 +1,54 @@
<script setup lang="ts">
import DOMPurify from 'dompurify';
import beautify from 'js-beautify';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const inputHtml = ref('');
const outputHtml = computed(() => {
const cleanedHtml = DOMPurify.sanitize(inputHtml.value ?? '',
{
ALLOWED_ATTR: [
'href', 'src',
'width', 'height',
'alt',
'colspan', 'rowspan',
],
FORBID_TAGS: ['form', 'span'],
ALLOW_DATA_ATTR: false,
ALLOW_ARIA_ATTR: false,
RETURN_DOM: true,
}).outerHTML;
return beautify.html(cleanedHtml, {
unformatted: ['code', 'pre', 'em', 'strong', 'span'],
indent_inner_html: true,
indent_char: ' ',
indent_size: 2,
eol: '\n',
});
});
</script>
<template>
<div>
<c-input-text
v-model:value="inputHtml"
multiline raw-text
placeholder="Your HTML content..."
rows="8"
autofocus
label="Your HTML to clean (can paste from clipboard):"
paste-html
/>
<n-divider />
<n-form-item label="Output cleaned HTML:">
<TextareaCopyable
:value="outputHtml"
multiline
language="html"
:word-wrap="true"
/>
</n-form-item>
</div>
</template>

View file

@ -0,0 +1,12 @@
import { BrandHtml5 } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Html cleaner',
path: '/html-cleaner',
description: 'Clean HTML',
keywords: ['html', 'cleaner'],
component: () => import('./html-cleaner.vue'),
icon: BrandHtml5,
createdAt: new Date('2024-02-25'),
});

View file

@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as htmlCleaner } from './html-cleaner';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@ -107,6 +108,7 @@ export const toolsByCategory: ToolCategory[] = [
listConverter,
tomlToJson,
tomlToYaml,
htmlCleaner,
],
},
{