-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
166 lines (148 loc) · 4 KB
/
index.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!doctype html><html lang=en-QS class='fixed'><meta id=ݽ charset=utf-8>
<meta name=viewport content="width=device-width, height=device-height, initial-scale=1">
<title>Markup2 Demo</title>
<script src=langs.js></script>
<script src=parse.js></script>
<script src=legacy.js></script>
<script src=render.js></script>
<script src=runtime.js></script>
<script src=helpers.js></script>
<link rel=stylesheet href=markup.css>
<script src=testing/textarea.js></script>
<link rel=stylesheet href=testing/common.css>
<script src=testing/tree.js></script>
<link rel=stylesheet href=testing/tree.css>
<style>
#\$output {
border: 3px solid orange;
padding: 4px;
overflow-y: auto;
user-select: contain;
}
#\$inputs {
flex-wrap: wrap;
gap: .25em;
background: #222;
color: #FFF;
padding: 2px;
}
label {
align-self: center;
font-weight: bold;
}
#\$output > textarea.plaintext {
resize: none;
display: block;
width: -webkit-fill-available;
width: -moz-available;
width: stretch;
}
textarea-container.textarea-nowrap {
padding-bottom: calc(15px + 2px);
}
textarea-container.textarea-nowrap > textarea {
white-space: pre;
overflow-y: auto;
overflow-x: scroll;
height: calc(100% + 15px);
}
</style>
<body class='Col'>
<script src=testing/nav.js></script>
<main class='fill Split'>
<input-pane class='Col'>
<div class='Row' id=$inputs>
<select id=$lang value=12y2>
<option> 12y2
<option> 12y
<option> bbcode
<option> plaintext
<option> json
</select>
<label>Wrap:<input type=checkbox id=$wrap checked></label>
<span class='fill'></span>
<select id=$display value=render>
<option> render
<option> nodes
<option> json
<option> testcase
</select>
</div>
<textarea-container class='limit'>
<textarea id=$input></textarea>
</textarea-container>
</input-pane>
<output-pane class='Col'>
<table-overflow><table class='data'>
<tr>
<th> <th> parse <th> render <th> layout <th> total
<tr>
<th> ms
<td> <time id=$time1 datetime=Z></time>
<td> <time id=$time2 datetime=Z></time>
<td> <time id=$time3 datetime=Z></time>
<td> <time id=$time4 datetime=Z></time>
</table></table-overflow>
<span id=$count></span>
<span id=$output class='Markup limit'></span>
</output-pane>
</main>
<script>
Markup.langs.include({
langs: {
json: text=>JSON.parse(text)
}
})
function show_time(elem, ms) {
elem.dateTime = (ms/1000).toFixed(4)+' s'
elem.textContent = ms.toFixed(1)
}
window.onerror = (...x)=>alert(x)
function update() {
//Markup.convert_lang($input.value, $lang.value, $output)
let t0, t1, t2, t3
t0 = performance.now()
let tree = Markup.langs.parse($input.value, $lang.value)
t1 = performance.now()
function output_text(text) {
let x = document.createElement('textarea')
let b = document.createElement('button')
b.textContent = 'Copy'
b.onclick = e=>{
navigator.clipboard.writeText(x.value)
}
x.value = text
x.className = 'plaintext'
$output.replaceChildren(b, x)
}
if ('render'==$display.value) {
$output.replaceChildren(Markup.renderer.render(tree))
} else if ('nodes'==$display.value) {
let e = draw_tree(tree)
$output.replaceChildren(e)
} else if ('json'==$display.value) {
output_text(JSON.stringify(tree))
} else if ('testcase'==$display.value) {
output_text("🟩 title here\n"+$input.value.replace(/🟩/g, "🟨")+"\n"+"🟩 "+JSON.stringify(tree))
}
//console.log(textarea, $output.contentEditable)
//if (textarea != ($output.contentEditable=='true'))
// $output.contentEditable = textarea ? 'true' : 'false'
t2 = performance.now()
$output.scrollHeight
t3 = performance.now()
show_time($time1, t1-t0)
show_time($time2, t2-t1)
show_time($time3, t3-t2)
show_time($time4, t3-t0)
}
$lang.onchange = update
$display.onchange = update
$wrap.onchange = ev=>{
$input.parentNode.classList.toggle('textarea-nowrap', !$wrap.checked)
textarea_resize($input)
}
$wrap.onchange()
setup_textarea($input, update)
update()
</script>