jotdown/examples/jotdown_wasm/index.html

33 lines
1.2 KiB
HTML
Raw Normal View History

2023-02-05 13:41:11 -05:00
<select id="fmt"><option value="preview">preview</option><option value="html">html</option></select>
<div id="jotdown" style="display:flex;">
<script type="module">
import init, { jotdown_render } from './pkg/jotdown_wasm.js';
await init();
let output = document.getElementById("output");
let input = document.getElementById("input");
let fmt = document.getElementById("fmt");
function render() {
let html = jotdown_render(input.innerText);
if (fmt.value == "html") {
output.classList.add("verbatim")
output.innerText = html;
} else if (fmt.value == "preview") {
output.classList.remove("verbatim")
output.innerHTML = html;
}
}
render()
input.onkeyup = render;
fmt.onchange = render;
// auto focus on input on load
setTimeout(() => { input.focus(); }, 0);
</script>
<pre id="input" contenteditable="true" placeholder="Input djot here" style="width:50%;height:100%;min-height:8em;max-height:20em;resize:none;margin:0">*Hello world!*</pre>
2023-03-26 16:59:26 -04:00
<pre id="output" readonly style="width:50%;height:100%;margin:0;min-height:8em;max-height:20em"></pre>
2023-02-05 13:41:11 -05:00
</div>