-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml.js
101 lines (100 loc) · 2.75 KB
/
html.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
class NMUc {
constructor (text="") {
this.text = text;
let tags = this.P_read(text);
let pars = this.P_parse(tags);
console.log(pars);
}
P_parse(ret) {
console.log(ret)
let strc = [];
let i = 0;
let child = [];
let tflag = false;
while (i<ret.length) {
console.log(0)
if (ret[i].type=="open") {
let ocnt = 0;
let tagname = ret[i].text;
let schild = i;
i++;
if (ret[i].type=="open") {
i++;
ocnt++;
}
else if (ret[i].type=="close") {
if (ocnt==0) {
i++;
console.log(schild,i)
strc.push({tag:tagname,child:ret.slice(0,10)});
continue;
}
else {
i++;
ocnt--;
}
}
else {
child.push(ret[i]);
i++;
}
}
i++;
}
return strc;
}
P_read(text) {
let t = text;
let i = 0;
let ret = [];
let tag = "";
while (t.length>i) {
if (t[i]=="<"&&t[i+1]!="/") {
if (tag.length>0) {
ret.push({type:"text",text:tag});
tag = "";
}
while (t.length>i) {
if (t[i]==">") {
tag += t[i];
ret.push({type:"open",text:tag});
tag = "";
i++;
break;
}
tag += t[i];
i++;
}
}
else if (t[i]=="<"&&t[i+1]=="/") {
if (tag.length>0) {
ret.push({type:"text",text:tag});
tag = "";
}
while (t.length>i) {
if (t[i]==">") {
tag += t[i];
ret.push({type:"close",text:tag});
tag = "";
i++;
break;
}
tag += t[i];
i++;
}
}
else {
tag+=t[i];
i++;
}
}
return ret;
}
}
function start(data) {
console.log("")
console.log(data);
console.log("----------------------------------------------");
let rt = new NMUc(data);
}
start(`<html><meta charset="utf-8">abv</html>`);