-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnicehtml.js
More file actions
24 lines (22 loc) · 928 Bytes
/
nicehtml.js
File metadata and controls
24 lines (22 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import * as wasm from './nicehtml_transpiler/pkg/nicehtml_transpiler.js';
// Start loading the WASM module
const wasmPromise = wasm.default();
// Fetch the scripts
const scripts = document.querySelectorAll('script[type="text/nicehtml"]');
const scriptPromises = Array.from(scripts).map((script) => {
if (script.src) {
// Fetch the script content
return fetch(script.src + '?timestamp=' + Date.now())
.then(response => response.text())
.catch(error => console.error('Error loading script:', error));
} else {
// Use the inline script content
return Promise.resolve(script.textContent);
}
});
// Wait for the WASM module and scripts to load
Promise.all([wasmPromise, ...scriptPromises])
.then(([wasmModule, ...scriptContents]) => {
console.log('Start rendering scripts');
scriptContents.forEach(content => wasm.transpile(content));
});