Compare commits

..
Author SHA1 Message Date
ShareVB f0c255d2f2 fix: lint 2024-12-15 19:47:20 +01:00
ShareVB 12a974de42 Merge remote-tracking branch 'origin/main' into feat/html-cleaner 2024-12-15 19:37:00 +01:00
ShareVB 07e53f0e2f fix: paste-html 2024-12-15 19:33:46 +01:00
ShareVB ba84e82a8e chore(github workflows): ci and e2e tests: try updating to node 20 2024-04-06 12:17:34 +02:00
ShareVB fbde97572f chore(github workflows): ci and e2e tests: try updating to node 20 2024-04-06 11:58:43 +02:00
sharevb c0c5cfda87 feat(new tool): html cleaner
HTML Cleaner (with paste html)
Fix #537
2024-04-06 11:52:42 +02:00
14 changed files with 573 additions and 740 deletions

No files matched your search

+4 -3
View File
@@ -85,6 +85,7 @@ declare module '@vue/runtime-core' {
HashText: typeof import('./src/tools/hash-text/hash-text.vue')['default']
HmacGenerator: typeof import('./src/tools/hmac-generator/hmac-generator.vue')['default']
'Home.page': typeof import('./src/pages/Home.page.vue')['default']
HtmlCleaner: typeof import('./src/tools/html-cleaner/html-cleaner.vue')['default']
HtmlEntities: typeof import('./src/tools/html-entities/html-entities.vue')['default']
HtmlWysiwygEditor: typeof import('./src/tools/html-wysiwyg-editor/html-wysiwyg-editor.vue')['default']
HttpStatusCodes: typeof import('./src/tools/http-status-codes/http-status-codes.vue')['default']
@@ -103,7 +104,6 @@ declare module '@vue/runtime-core' {
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
IpIncludeExclude: typeof import('./src/tools/ip-include-exclude/ip-include-exclude.vue')['default']
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
@@ -136,14 +136,14 @@ declare module '@vue/runtime-core' {
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NFormItem: typeof import('naive-ui')['NFormItem']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NSpace: typeof import('naive-ui')['NSpace']
NTable: typeof import('naive-ui')['NTable']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
@@ -162,6 +162,7 @@ declare module '@vue/runtime-core' {
RouterView: typeof import('vue-router')['RouterView']
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
+2 -2
View File
@@ -46,6 +46,7 @@
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/figlet": "^1.5.8",
"@types/js-beautify": "^1.14.3",
"@types/markdown-it": "^13.0.7",
"@vicons/material": "^0.12.0",
"@vicons/tabler": "^0.12.0",
@@ -54,7 +55,6 @@
"@vueuse/router": "^10.0.0",
"bcryptjs": "^2.4.3",
"change-case": "^4.1.2",
"cidr-tools": "^11.0.2",
"colord": "^2.9.3",
"composerize-ts": "^0.6.2",
"country-code-lookup": "^0.1.0",
@@ -71,7 +71,7 @@
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"ip-matching": "^2.1.2",
"js-beautify": "^1.15.1",
"js-base64": "^3.7.6",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
+468 -517
View File
File diff suppressed because it is too large. Load diff
@@ -128,7 +128,7 @@ function activateOption(option: PaletteOption) {
<c-input-text ref="inputRef" v-model:value="searchPrompt" raw-text placeholder="Type to search a tool or a command..." autofocus clearable />
<div v-for="(options, category) in filteredSearchResult" :key="category">
<div ml-3 mt-3 text-sm font-bold text-primary op-60>
<div ml-3 mt-3 text-sm text-primary font-bold op-60>
{{ category }}
</div>
<command-palette-option v-for="option in options" :key="option.name" :option="option" :selected="selectedOptionIndex === getOptionIndex(option)" @activated="activateOption" />
+54
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>
+12
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'),
});
+3 -10
View File
@@ -1,13 +1,13 @@
import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as ipIncludeExclude } from './ip-include-exclude';
import { tool as emailNormalizer } from './email-normalizer';
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 xmlToJson } from './xml-to-json';
import { tool as jsonToXml } from './json-to-xml';
import { tool as regexTester } from './regex-tester';
@@ -114,6 +114,7 @@ export const toolsByCategory: ToolCategory[] = [
listConverter,
tomlToJson,
tomlToYaml,
htmlCleaner,
xmlToJson,
jsonToXml,
markdownToHtml,
@@ -165,15 +166,7 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Network',
components: [
ipv4SubnetCalculator,
ipv4AddressConverter,
ipv4RangeExpander,
ipIncludeExclude,
macAddressLookup,
macAddressGenerator,
ipv6UlaGenerator,
],
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
},
{
name: 'Math',
-12
View File
@@ -1,12 +0,0 @@
import { UnfoldMoreOutlined } from '@vicons/material';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'IP Subnets Exclude Calculator',
path: '/ip-include-exclude',
description: 'Substract a disallowed IP Ranges/Mask/CIDR list from an allowed IP Ranges/Mask/CIDR list',
keywords: ['ip', 'allowed', 'disallowed', 'include', 'exclude', 'subnet', 'cidr'],
component: () => import('./ip-include-exclude.vue'),
icon: UnfoldMoreOutlined,
createdAt: new Date('2024-08-15'),
});
@@ -1,63 +0,0 @@
import { describe, expect, it } from 'vitest';
import { substractCIDRs } from './ip-include-exclude.service';
describe('ip-include-exclude', () => {
describe('substractCIDRs', () => {
it('should return error on invalid values', () => {
expect(substractCIDRs({ allowedRanges: '192.168.0.', disallowedRanges: '' })).to.deep.eq({ // NOSONAR
allowedCIDRs: [],
allowedSubnets: [],
disallowedSubnets: [],
error: 'Error: Invalid IP (range/subnetwork)',
});
});
it('should return correct substractions and subnets', () => {
expect(substractCIDRs({ allowedRanges: '192.168.3.0/24', disallowedRanges: '' })).to.deep.eq({ // NOSONAR
allowedCIDRs: ['192.168.3.0/24'], // NOSONAR
allowedSubnets: [{ cidr: '192.168.3.0/24', end: '192.168.3.255', start: '192.168.3.0' }], // NOSONAR
disallowedSubnets: [],
error: '',
});
expect(substractCIDRs({ allowedRanges: '192.168.2.0/24', disallowedRanges: '192.168.2.1' })).to.deep.eq({ // NOSONAR
allowedCIDRs: ['192.168.2.0/32', // NOSONAR
'192.168.2.2/31', // NOSONAR
'192.168.2.4/30', // NOSONAR
'192.168.2.8/29', // NOSONAR
'192.168.2.16/28', // NOSONAR
'192.168.2.32/27', // NOSONAR
'192.168.2.64/26', // NOSONAR
'192.168.2.128/25'], // NOSONAR
allowedSubnets: [
{ cidr: '192.168.2.0/24', end: '192.168.2.255', start: '192.168.2.0' }, // NOSONAR
],
disallowedSubnets: [
{ cidr: '192.168.2.1/32', end: '192.168.2.1', start: '192.168.2.1' }, // NOSONAR
],
error: '',
});
expect(substractCIDRs({ allowedRanges: '192.168.12.0/24', disallowedRanges: '192.168.12.1-192.168.12.10, 192.168.12.34' })).to.deep.eq({ // NOSONAR
allowedCIDRs: ['192.168.12.0/32', // NOSONAR
'192.168.12.11/32', // NOSONAR
'192.168.12.12/30', // NOSONAR
'192.168.12.16/28', // NOSONAR
'192.168.12.32/31', // NOSONAR
'192.168.12.35/32', // NOSONAR
'192.168.12.36/30', // NOSONAR
'192.168.12.40/29', // NOSONAR
'192.168.12.48/28', // NOSONAR
'192.168.12.64/26', // NOSONAR
'192.168.12.128/25'], // NOSONAR
allowedSubnets: [{ cidr: '192.168.12.0/24', end: '192.168.12.255', start: '192.168.12.0' }], // NOSONAR
disallowedSubnets: [
{ cidr: '192.168.12.1/32', end: '192.168.12.1', start: '192.168.12.1' }, // NOSONAR
{ cidr: '192.168.12.2/31', end: '192.168.12.3', start: '192.168.12.2' }, // NOSONAR
{ cidr: '192.168.12.4/30', end: '192.168.12.7', start: '192.168.12.4' }, // NOSONAR
{ cidr: '192.168.12.8/31', end: '192.168.12.9', start: '192.168.12.8' }, // NOSONAR
{ cidr: '192.168.12.10/32', end: '192.168.12.10', start: '192.168.12.10' }, // NOSONAR
{ cidr: '192.168.12.34/32', end: '192.168.12.34', start: '192.168.12.34' }, // NOSONAR
],
error: '',
});
});
});
});
@@ -1,49 +0,0 @@
import type { IPMask } from 'ip-matching';
import { getMatch } from 'ip-matching';
import { excludeCidr } from 'cidr-tools';
function convertToCIDR(mask: IPMask) {
const subnet = mask.convertToSubnet();
if (!subnet) {
return { cidr: mask.toString(), start: '', end: '' };
}
return {
cidr: subnet.toString(),
start: subnet.getFirst().toString(),
end: subnet.getLast().toString(),
};
}
export function substractCIDRs(
{ allowedRanges, disallowedRanges }:
{
allowedRanges: string
disallowedRanges: string
}) {
try {
const allowedRangesMatchMasks = allowedRanges.split(/\s*[,;|]+\s*/g) // NOSONAR
.filter(range => range)
.flatMap(range => getMatch(range)?.convertToMasks() || []);
const disallowedRangesMatchMasks = disallowedRanges.split(/\s*[,;|]+\s*/g) // NOSONAR
.filter(range => range)
.flatMap(range => getMatch(range)?.convertToMasks() || []);
const allowedSubnets = allowedRangesMatchMasks.map(convertToCIDR);
const disallowedSubnets = disallowedRangesMatchMasks.map(convertToCIDR);
return {
error: '',
allowedSubnets,
disallowedSubnets,
allowedCIDRs: excludeCidr(allowedSubnets.map(net => net.cidr), disallowedSubnets.map(net => net.cidr)),
};
}
catch (e: any) {
return {
error: e.toString(),
allowedSubnets: [],
disallowedSubnets: [],
allowedCIDRs: [],
};
}
}
@@ -1,80 +0,0 @@
<script setup lang="ts">
import { useStorage } from '@vueuse/core';
import { substractCIDRs } from './ip-include-exclude.service';
import SpanCopyable from '@/components/SpanCopyable.vue';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const allowedRanges = useStorage('ip-inc-exc:allow', '192.168.0.1/24'); // NOSONAR
const disallowedRanges = useStorage('ip-inc-exc:disallow', '192.168.0.6'); // NOSONAR
const result = computed(() => substractCIDRs({
allowedRanges: allowedRanges.value, disallowedRanges: disallowedRanges.value,
}));
</script>
<template>
<div>
<c-input-text
v-model:value="allowedRanges"
label="AllowedIPs (IPv4/6 CIDR/Range/Mask/Wildcard)"
placeholder="An IPv4/6 CIDR/Range/Mask/Wildcard..."
mb-4
/>
<c-input-text
v-model:value="disallowedRanges"
label="DisallowedIPs (IPv4/6 CIDR/Range/Mask/Wildcard)"
placeholder="An IPv4/6 CIDR/Range/Mask/Wildcard..."
mb-4
/>
<n-divider />
<c-alert v-if="result.error">
{{ result.error }}
</c-alert>
<div v-if="!result.error">
<n-form-item label="Final AllowedIPs:">
<TextareaCopyable :value="result.allowedCIDRs.join(', ')" />
</n-form-item>
<n-divider />
<c-card title="Allowed Subnets">
<n-table>
<tbody>
<tr v-for="{ cidr, start, end } in result.allowedSubnets" :key="cidr">
<td font-bold>
<SpanCopyable :value="cidr" />
</td>
<td>
<SpanCopyable :value="start" />
</td>
<td>
<SpanCopyable :value="end" />
</td>
</tr>
</tbody>
</n-table>
</c-card>
<c-card title="Disallowed Subnets">
<n-table>
<tbody>
<tr v-for="{ cidr, start, end } in result.disallowedSubnets" :key="cidr">
<td font-bold>
<SpanCopyable :value="cidr" />
</td>
<td>
<SpanCopyable :value="start" />
</td>
<td>
<SpanCopyable :value="end" />
</td>
</tr>
</tbody>
</n-table>
</c-card>
</div>
</div>
</template>
+27 -1
View File
@@ -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<HTMLTextAreaElement>();
const inputRef = ref<HTMLInputElement>();
const inputWrapperRef = ref<HTMLElement>();
interface HTMLElementWithValue {
value?: string
}
function onPasteInputHtml(evt: ClipboardEvent) {
if (!pasteHtml.value) {
return false;
}
const target = (evt.target as HTMLElementWithValue);
if (!target) {
return false;
}
const textHtmlData = evt.clipboardData?.getData('text/html');
if (textHtmlData && textHtmlData !== '') {
evt.preventDefault();
value.value = textHtmlData;
return true;
}
return false;
}
watch(
[value, autosize, multiline, inputWrapperRef, textareaRef],
() => nextTick(() => {
@@ -171,6 +195,7 @@ defineExpose({
:autocorrect="autocorrect ?? (rawText ? 'off' : undefined)"
:spellcheck="spellcheck ?? (rawText ? false : undefined)"
:rows="rows"
@paste="onPasteInputHtml"
/>
<input
@@ -192,6 +217,7 @@ defineExpose({
:autocomplete="autocomplete ?? (rawText ? 'off' : undefined)"
:autocorrect="autocorrect ?? (rawText ? 'off' : undefined)"
:spellcheck="spellcheck ?? (rawText ? false : undefined)"
@paste="onPasteInputHtml"
>
<c-button v-if="clearable && value" variant="text" circle size="small" @click="value = ''">
+1 -1
View File
@@ -151,7 +151,7 @@ function onSearchInput() {
>
<div flex-1 truncate>
<slot name="displayed-value">
<input v-if="searchable && isOpen" ref="searchInputRef" v-model="searchQuery" type="text" placeholder="Search..." class="search-input" w-full lh-normal color-current @input="onSearchInput">
<input v-if="searchable && isOpen" ref="searchInputRef" v-model="searchQuery" type="text" placeholder="Search..." class="search-input" w-full color-current lh-normal @input="onSearchInput">
<span v-else-if="selectedOption" lh-normal>
{{ selectedOption.label }}
</span>
+1 -1
View File
@@ -39,7 +39,7 @@ const headers = computed(() => {
<template>
<div class="relative overflow-x-auto rounded">
<table class="w-full border-collapse text-left text-sm text-gray-500 dark:text-gray-400" role="table" :aria-label="description">
<thead v-if="!hideHeaders" class="bg-#ffffff uppercase text-gray-700 dark:bg-#333333 dark:text-gray-400" border-b="1px solid dark:transparent #efeff5">
<thead v-if="!hideHeaders" class="bg-#ffffff text-gray-700 uppercase dark:bg-#333333 dark:text-gray-400" border-b="1px solid dark:transparent #efeff5">
<tr>
<th v-for="header in headers" :key="header.key" scope="col" class="px-6 py-3 text-xs">
{{ header.label }}