feat: add XML and HTML formatting support (#721)

This commit is contained in:
wanghongenpin
2026-04-04 00:59:46 +08:00
parent 87fb5a7f21
commit bcd8af3e2d
11 changed files with 343 additions and 33 deletions

View File

@@ -0,0 +1,18 @@
import 'package:xml/xml.dart';
class XML {
/// 格式化 XML
static String pretty(String xmlString) {
if (xmlString.trim().isEmpty || !xmlString.contains('<')) {
return xmlString;
}
try {
final document = XmlDocument.parse(xmlString);
return document.toXmlString(pretty: true, indent: ' ');
} catch (_) {
return xmlString;
}
}
}