Skip to content

Commit 8fed1bb

Browse files
committed
Merge branch 'feat/html-cleaner' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
2 parents 310073a + ba84e82 commit 8fed1bb

File tree

5 files changed

+129
-2
lines changed

5 files changed

+129
-2
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"@types/markdown-it": "^13.0.7",
101101
"@types/figlet": "^1.5.8",
102102
"@types/sshpk": "^1.17.4",
103+
"@types/js-beautify": "^1.14.3",
103104
"@vicons/material": "^0.12.0",
104105
"@vicons/tabler": "^0.12.0",
105106
"@vueuse/core": "^10.11.1",
@@ -192,6 +193,7 @@
192193
"js-base64": "^3.7.7",
193194
"ical.js": "^2.0.1",
194195
"js-base64": "^3.7.7",
196+
"js-beautify": "^1.15.1",
195197
"json5": "^2.2.3",
196198
"jsonpath": "^1.1.1",
197199
"jsonar-mod": "^1.9.0",

pnpm-lock.yaml

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script setup lang="ts">
2+
import DOMPurify from 'dompurify';
3+
import beautify from 'js-beautify';
4+
import TextareaCopyable from '@/components/TextareaCopyable.vue';
5+
6+
const inputHtml = ref('');
7+
const outputHtml = computed(() => {
8+
const cleanedHtml = DOMPurify.sanitize(inputHtml.value ?? '',
9+
{
10+
ALLOWED_ATTR: [
11+
'href', 'src',
12+
'width', 'height',
13+
'alt',
14+
'colspan', 'rowspan',
15+
],
16+
FORBID_TAGS: ['form', 'span'],
17+
ALLOW_DATA_ATTR: false,
18+
ALLOW_ARIA_ATTR: false,
19+
RETURN_DOM: true,
20+
}).outerHTML;
21+
return beautify.html(cleanedHtml, {
22+
unformatted: ['code', 'pre', 'em', 'strong', 'span'],
23+
indent_inner_html: true,
24+
indent_char: ' ',
25+
indent_size: 2,
26+
eol: '\n',
27+
});
28+
});
29+
</script>
30+
31+
<template>
32+
<div>
33+
<c-input-text
34+
v-model:value="inputHtml"
35+
multiline raw-text
36+
placeholder="Your HTML content..."
37+
rows="8"
38+
autofocus
39+
label="Your HTML to clean (can paste from clipboard):"
40+
paste-html
41+
/>
42+
43+
<n-divider />
44+
45+
<n-form-item label="Output cleaned HTML:">
46+
<TextareaCopyable
47+
:value="outputHtml"
48+
multiline
49+
language="html"
50+
:word-wrap="true"
51+
/>
52+
</n-form-item>
53+
</div>
54+
</template>

src/tools/html-cleaner/index.ts

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

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ import { tool as dockerComposeValidator } from './docker-compose-validator';
114114
import { tool as ecdsaKeyPairGenerator } from './ecdsa-key-pair-generator';
115115
import { tool as ed25519KeyPairGenerator } from './ed25519-key-pair-generator';
116116
import { tool as fileType } from './file-type';
117+
import { tool as htmlCleaner } from './html-cleaner';
117118
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
118119
import { tool as numeronymGenerator } from './numeronym-generator';
119120
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -292,6 +293,7 @@ export const toolsByCategory: ToolCategory[] = [
292293
xmlToJson,
293294
jsonToXml,
294295
gzipConverter,
296+
htmlCleaner,
295297
],
296298
},
297299
{

0 commit comments

Comments
 (0)