-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (19 loc) · 795 Bytes
/
index.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
function $create(node) {
node = node.trim();
let startingTag = node.match(/<(?:[^>\s]+)/)[0];
startingTag = startingTag.slice(1, startingTag.length);
let attributes =
node.slice(startingTag.length + 1, startingTag.length + 2) !== ">"
?
(node.slice(startingTag.length + 1).match(/([^>]+)/)[0]).replace(/\s/g, "").replace(/\([\"\']/g, "(#$#").replace(/[\"\']\)/g, "#$#)").replace(/\\[\"\']/g, "#$#").split(/[\"\'](?!url\()|=[\"\']/g)
:
"";
let HTML = node.match(/>([^]*)</)[0];
HTML = HTML.slice(1, HTML.length - 1);
let element = document.createElement(startingTag);
for(let i = 0; i < attributes.length - 1; i+=2) {
element.setAttribute(attributes[i], attributes[i + 1].replace(/#\$#/g, "\'").replace(/%20/g, " "));
}
element.innerHTML = HTML;
return element;
}