-
-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathhtml_spec.js
More file actions
82 lines (73 loc) · 2.75 KB
/
Copy pathhtml_spec.js
File metadata and controls
82 lines (73 loc) · 2.75 KB
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
82
import {XMLParser, XMLBuilder} from "../src/fxp.js";
describe("XMLParser", function() {
it("should parse HTML with basic entities, <pre>, <script>, <br>", function() {
Object.prototype.something = 'strange';
const html = `
<html lang="en">
<head>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-80202630-2');
</script>
<title>Fast XML Parser</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/jquery-confirm.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="static/js/jquery-3.2.1.min.js"></script>
<style>
.CodeMirror{
height: 100%;
width: 100%;
}
</style>
</head>
<body role="document" style="background-color: #2c3e50;">
<h1>Heading</h1>
<hr>
<h2>&inr;</h2>
<pre>
<h1>Heading</h1>
<hr>
<h2>&inr;</h2>
</pre>
<script>
let highlightedLine = null;
let editor;
<!-- this should not be parsed separately -->
function updateLength(){
const xmlData = editor.getValue();
$("#lengthxml")[0].innerText = xmlData.replace(/>\s*</g, "><").length;
}
</script>
</body>
</html>`;
const parsingOptions = {
ignoreAttributes: false,
preserveOrder: true,
unpairedTags: ["hr", "br", "link", "meta"],
stopNodes : [ "*.pre", "*.script"],
processEntities: true,
htmlEntities: true,
};
const parser = new XMLParser(parsingOptions);
let result = parser.parse(html);
// console.log(JSON.stringify(result, null,4));
const builderOptions = {
ignoreAttributes: false,
format: true,
preserveOrder: true,
suppressEmptyNode: false,
unpairedTags: ["hr", "br", "link", "meta"],
stopNodes : [ "*.pre", "*.script"],
}
const builder = new XMLBuilder(builderOptions);
let output = builder.build(result);
// console.log(output);
output = output.replace('₹','&inr;');
expect(output.replace(/\s+/g, "")).toEqual(html.replace(/\s+/g, ""));
});
});