-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat-xml.html
81 lines (71 loc) · 2.76 KB
/
format-xml.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!--
Copyright (c) 2020-2021 Valère Monseur
Licensed under the terms of the MIT license - http://opensource.org/licenses/MIT
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="icon" href="/favicon.ico" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap"
/>
<link rel="stylesheet" href="css/format-xml.css" />
<script src="js/formatXML.js"></script>
<title>Format XML</title>
</head>
<body>
<textarea id="text1" wrap="off" autofocus></textarea>
<div id="text2" ondblclick="switchMode()"></div>
<script>
var mode = "format,color";
var text1 = document.getElementById("text1");
var text2 = document.getElementById("text2");
text1.onkeyup = text1.onpaste = text1.onchange = FormatToXML;
function FormatToXML() {
/* XML = text1.value.replace(/(\r\n|\n|\r)/gm, " ").replace(/>\s+</g, "><").trim(); */
XML = text1.value.replace(/>[\s\r\n]+</gm, "><").trim();
if (mode.includes("format")) {
XML = formatXML(XML)
.replace(/&/g, "&")
.replace(/ /g, " ")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/\r\n/g, "<br />");
} else {
XML = XML.replace(/&/g, "&")
.replace(/ /g, " ")
.replace(/</g, "<")
.replace(/>/g, ">");
}
if (mode.includes("color")) {
XML = XML.replace(
/</g,
"<span class='tag'><</span><span class='tagname'>"
).replace(/>/g, "</span><span class='tag'>></span>");
}
text2.innerHTML = XML;
}
function switchMode() {
switch (mode) {
case "format,color":
mode = "format";
break;
case "format":
mode = "color";
break;
case "color":
mode = "none";
break;
case "none":
mode = "format,color";
break;
}
text1.onchange();
}
</script>
</body>
</html>