mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 10:51:26 +01:00
Better XML beautify
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
1
src-web/modules.d.ts
vendored
1
src-web/modules.d.ts
vendored
@@ -1 +1,2 @@
|
||||
declare module 'format-graphql';
|
||||
declare module 'xml-beautify';
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user