-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitHTO.js
More file actions
46 lines (35 loc) · 748 Bytes
/
Copy pathinitHTO.js
File metadata and controls
46 lines (35 loc) · 748 Bytes
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
const fs = require('fs');
const parse5 = require('parse5');
let HTO = {};
function readFile(filePath, callback) {
fs.readFile(filePath, 'utf8', function(err, data) {
if (err) throw err;
callback(data);
});
}
function parse(file) {
let ast = parse5.parseFragment(file);
return ast;
}
function initHTO(root) {
HTO = root;
if (HTO.childNodes) {
_traverse(HTO, -1);
}
return HTO;
}
function _traverse(node, indentBefore) {
node.indentSize = indentBefore;
delete node.parentNode;
indentBefore ++;
if (node.childNodes) {
for (let childNode of node.childNodes) {
_traverse(childNode, indentBefore);
}
}
}
module.exports = {
readFile: readFile,
parse: parse,
initHTO: initHTO
};