-
Notifications
You must be signed in to change notification settings - Fork 144
/
example.html
39 lines (34 loc) · 1.35 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<title>@ruby/prism</title>
</head>
<body style="margin: 0;">
<div style="display: grid; grid-template-columns: 1fr 1fr;">
<div>
<textarea id="input" style="box-sizing: border-box; width: 100%; height: 100vh; resize: none; vertical-align: top;"></textarea>
</div>
<div style="height: 100vh; overflow-y: scroll;">
<code><pre id="output" style="margin: 0; padding: 1em;"></pre></code>
</div>
</div>
<script type="module">
import { WASI } from "https://unpkg.com/@bjorn3/browser_wasi_shim@latest/dist/index.js";
import { parsePrism } from "https://unpkg.com/@ruby/prism@latest/src/parsePrism.js";
const wasm = await WebAssembly.compileStreaming(fetch("https://unpkg.com/@ruby/prism@latest/src/prism.wasm"));
const wasi = new WASI([], [], []);
const instance = await WebAssembly.instantiate(wasm, { wasi_snapshot_preview1: wasi.wasiImport });
wasi.initialize(instance);
let timeout = null;
const input = document.getElementById("input");
const output = document.getElementById("output");
input.addEventListener("input", function (event) {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function () {
const result = parsePrism(instance.exports, event.target.value);
output.textContent = JSON.stringify(result, null, 2);
}, 250);
});
</script>
</body>
</html>