fix: remove xml viewer

This commit is contained in:
Ibrahima G. Coulibaly
2025-07-09 02:16:29 +01:00
parent 57fe32d15f
commit 82df4ee475
8 changed files with 21 additions and 132 deletions

View File

@@ -1,4 +1,4 @@
import { tool as xmlXmlValidator } from './xml-validator/meta';
import { tool as xmlXmlBeautifier } from './xml-beautifier/meta';
import { tool as xmlXmlViewer } from './xml-viewer/meta';
export const xmlTools = [xmlXmlViewer, xmlXmlBeautifier, xmlXmlValidator];
export const xmlTools = [xmlXmlBeautifier, xmlXmlValidator];

View File

@@ -1,54 +0,0 @@
import { Box } from '@mui/material';
import React, { useState } from 'react';
import ToolContent from '@components/ToolContent';
import { ToolComponentProps } from '@tools/defineTool';
import ToolTextInput from '@components/input/ToolTextInput';
import ToolTextResult from '@components/result/ToolTextResult';
import { CardExampleType } from '@components/examples/ToolExamples';
import { prettyPrintXml } from './service';
import { InitialValuesType } from './types';
const initialValues: InitialValuesType = {};
const exampleCards: CardExampleType<InitialValuesType>[] = [
{
title: 'Pretty Print XML',
description: 'View and pretty-print a compact XML string.',
sampleText: '<root><item>1</item><item>2</item></root>',
sampleResult: `<root>\n <item>1</item>\n <item>2</item>\n</root>`,
sampleOptions: {}
}
];
export default function XmlViewer({
title,
longDescription
}: ToolComponentProps) {
const [input, setInput] = useState<string>('');
const [result, setResult] = useState<string>('');
const compute = (_values: InitialValuesType, input: string) => {
setResult(prettyPrintXml(input, {}));
};
return (
<ToolContent
title={title}
input={input}
inputComponent={
<ToolTextInput
value={input}
onChange={setInput}
placeholder="Paste or import XML here..."
/>
}
resultComponent={<ToolTextResult value={result} extension="xml" />}
initialValues={initialValues}
exampleCards={exampleCards}
getGroups={null}
setInput={setInput}
compute={compute}
toolInfo={{ title: `What is a ${title}?`, description: longDescription }}
/>
);
}

View File

@@ -1,13 +0,0 @@
import { defineTool } from '@tools/defineTool';
import { lazy } from 'react';
export const tool = defineTool('xml', {
name: 'XML Viewer',
path: 'xml-viewer',
icon: 'mdi:eye-outline',
description:
'View and pretty-print XML files or strings for easier reading and debugging.',
shortDescription: 'Pretty-print and view XML.',
keywords: ['xml', 'viewer', 'pretty print', 'format', 'inspect'],
component: lazy(() => import('./index'))
});

View File

@@ -1,23 +0,0 @@
import { InitialValuesType } from './types';
import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser';
export function prettyPrintXml(
input: string,
_options: InitialValuesType
): string {
const valid = XMLValidator.validate(input);
if (valid !== true) {
if (typeof valid === 'object' && valid.err) {
return `Invalid XML: ${valid.err.msg} (line ${valid.err.line}, col ${valid.err.col})`;
}
return 'Invalid XML';
}
try {
const parser = new XMLParser();
const obj = parser.parse(input);
const builder = new XMLBuilder({ format: true, indentBy: ' ' });
return builder.build(obj);
} catch (e: any) {
return `Invalid XML: ${e.message}`;
}
}

View File

@@ -1,3 +0,0 @@
export type InitialValuesType = {
// splitSeparator: string;
};

View File

@@ -1,18 +0,0 @@
import { expect, describe, it } from 'vitest';
import { prettyPrintXml } from './service';
describe('xml-viewer', () => {
it('pretty prints valid XML', () => {
const input = '<root><a>1</a><b>2</b></root>';
const result = prettyPrintXml(input, {});
expect(result).toContain('<root>');
expect(result).toContain(' <a>1</a>');
expect(result).toContain(' <b>2</b>');
});
it('returns error for invalid XML', () => {
const input = '<root><a>1</b></root>';
const result = prettyPrintXml(input, {});
expect(result).toMatch(/Invalid XML/i);
});
});