Better XML beautify

This commit is contained in:
Gregory Schier
2025-10-24 08:59:16 -07:00
parent 754ec0ba86
commit 17ddc76223
5 changed files with 70 additions and 81 deletions

View File

@@ -1,8 +1,12 @@
import xmlFormat from 'xml-formatter';
import XmlBeautify from 'xml-beautify';
import { invokeCmd } from './tauri';
const INDENT = ' ';
const xmlBeautifier = new XmlBeautify({
INDENT,
});
export async function tryFormatJson(text: string): Promise<string> {
if (text === '') return text;
@@ -16,9 +20,8 @@ export async function tryFormatJson(text: string): Promise<string> {
try {
return JSON.stringify(JSON.parse(text), null, 2);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// Nothing
console.log("JSON beautify failed", err);
}
return text;
@@ -28,9 +31,9 @@ export async function tryFormatXml(text: string): Promise<string> {
if (text === '') return text;
try {
return xmlFormat(text, { throwOnFailure: true, strictMode: false, indentation: INDENT });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return xmlBeautifier.beautify(text);
} catch (err) {
console.log("XML beautify failed", err);
return text;
}
}

View File

@@ -1 +1,2 @@
declare module 'format-graphql';
declare module 'xml-beautify';

View File

@@ -26,7 +26,7 @@
"@tanstack/react-query": "^5.90.5",
"@tanstack/react-router": "^1.133.13",
"@tanstack/react-virtual": "^3.13.12",
"@tauri-apps/api": "^2.8.0",
"@tauri-apps/api": "^2.9.0",
"@tauri-apps/plugin-clipboard-manager": "^2.3.0",
"@tauri-apps/plugin-dialog": "^2.4.0",
"@tauri-apps/plugin-fs": "^2.4.2",
@@ -66,7 +66,7 @@
"slugify": "^1.6.6",
"uuid": "^11.1.0",
"whatwg-mimetype": "^4.0.0",
"xml-formatter": "^3.6.3",
"xml-beautify": "^1.2.3",
"yaml": "^2.6.1"
},
"devDependencies": {