-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.html
49 lines (42 loc) · 1.71 KB
/
convert.html
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML to html.js</title>
<style>
*{margin: 0;}
body{background-color: #f5f5f5;}
.js {color: #444;}
.js .str{color: #082;}
.js .tag{color: #930;}
.js .T {color: #b08;}
</style>
<script type="module">
import {HTML, E} from "https://cdn.jsdelivr.net/gh/katsu-oh/html.js/html.min.js";
const params = new URLSearchParams(location.search);
const paramVar = params.get("var");
let newID = 0;
const iHTML = ++newID;
const iJS = ++newID;
const h = HTML(document.body);
h. $DIV;
h. $TEXTAREA. id(iHTML). placeholder`HTML to convert`. spellcheck`false`. autofocus;
h. s.width`49%`. s.height`99vh`. s.verticalAlign`bottom`. s.whiteSpace`pre`. s.resize`none`;
h. on.input(convert);
h. $;
h. $PRE;
h. s.width`49%`. s.height`99vh`. s.display`inline-block`. s.verticalAlign`bottom`;
h. s.marginLeft`1%`. s.marginBottom`4px`. s.overflow`auto`;
h. $CODE. id(iJS). class`js`. $;
h. $;
h. $;
h.publish();
function convert(event){
let js = HTML().HTML(E(iHTML).value.replace(/^[ \t]*/, "")).toLocaleString().replace(/^ *$/mg, "");
js = js.replace(/(^|`(?:\\.|.)*?`)([^`]*)(?=$|`)/g, (m, p1, p2) => p1 + p2.replace(/(?<!\Ws)\.(?=[^\n])/g, ". ")).replace(/<\//g, "<\\/");
if(paramVar){
js = js.replace(/^(?!$)/mg, paramVar + ". ").replace(/\.$/mg, ";");
}
let jsHtml = js.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
jsHtml = jsHtml.replace(/(^|`(?:\\.|.)*?`)([^`]*)(?=$|`)/g, (m, p1, p2) => "<span class='str'>" + p1 + "</span>" + p2.replace(/(?:^| |\n)\$.*?(?=\.|;)/g, "<span class='tag'>$&</span>").replace(/(?:^| |\n)T$/g, "<span class='T'>$&</span>"));
E(iJS).innerHTML = jsHtml;
}
</script>