-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.js
30 lines (30 loc) · 828 Bytes
/
string.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
/**
* Reverts the result of parse back to html code
* @param {Array} elementList The result of parse
* @returns The result of parse as a String
*/
export const stringify = (elementList) => {
let resultString = "";
for (let i of elementList) {
if (i.type == "text") {
resultString += i.text.replaceAll("<", "<").replaceAll(">", ">");
}
if (i.type == "html") {
resultString += `<${i.tag} `;
for (let a of i.attributes) {
resultString += `${a.attribute}="${a.value.replaceAll(
'"',
"""
)}" `;
}
resultString += ">";
if (i.innerHTML && i.innerHTML.length > 0) {
resultString += stringify(i.innerHTML);
}
if (!i.selfClosing) {
resultString += `</${i.tag}>`;
}
}
}
return resultString;
};