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 { html, RawHTML } from "https://esm.town/v/postpostscript/html";
import { hybridTaggedTemplateMethodAsync } from "https://esm.town/v/postpostscript/hybridTaggedTemplateMethod";
import { provideBlob } from "https://esm.town/v/postpostscript/provideBlob";
export { provideBlob } from "https://esm.town/v/postpostscript/provideBlob";
export function provideBlobToHtml(jsPromise: RawHTML, placeholder?: unknown) {
const id = "provideBlobHtml-" + Math.random().toString().slice(3);
return html`
<div id="${id}">
${placeholder}
<script>
const id = "${id}";
${jsPromise}
.then(blob => blob.text())
.then(html => {
const $div = document.createElement("div")
$div.innerHTML = html
$div.id = id
document.getElementById(id).replaceWith(...$div.children)
})
</script>
</div>
`;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 2, 2024