jotdown_wasm: add option to show events

provide 1:1 representation of events to help explore how events are
emitted
This commit is contained in:
Noah Hellman 2023-03-26 14:54:25 +02:00
parent f31398a796
commit f3732693c6
2 changed files with 18 additions and 4 deletions

View file

@ -1,6 +1,9 @@
<div id="jotdown" style="flex-grow:1;display:flex;flex-direction:column"> <div id="jotdown" style="flex-grow:1;display:flex;flex-direction:column">
<script type="module"> <script type="module">
import init, { jotdown_render } from './pkg/jotdown_wasm.js'; import init, {
jotdown_render,
jotdown_parse,
} from './pkg/jotdown_wasm.js';
await init(); await init();
let output = document.getElementById("output"); let output = document.getElementById("output");
@ -8,13 +11,15 @@
let fmt = document.getElementById("fmt"); let fmt = document.getElementById("fmt");
function render() { function render() {
let html = jotdown_render(input.innerText);
if (fmt.value == "html") { if (fmt.value == "html") {
output.classList.add("verbatim") output.classList.add("verbatim")
output.innerText = html; output.innerText = jotdown_render(input.innerText);
} else if (fmt.value == "events") {
output.classList.add("verbatim")
output.innerText = jotdown_parse(input.innerText);
} else if (fmt.value == "preview") { } else if (fmt.value == "preview") {
output.classList.remove("verbatim") output.classList.remove("verbatim")
output.innerHTML = html; output.innerHTML = jotdown_render(input.innerText);
} }
} }
@ -30,6 +35,7 @@
<select id="fmt"> <select id="fmt">
<option value="preview">preview</option> <option value="preview">preview</option>
<option value="html">html</option> <option value="html">html</option>
<option value="events">events</option>
</select> </select>
</div> </div>
<div id="panes" style="display:flex;height:100%;gap:1rem"> <div id="panes" style="display:flex;height:100%;gap:1rem">

View file

@ -12,3 +12,11 @@ pub fn jotdown_render(djot: &str) -> String {
.unwrap(); .unwrap();
html html
} }
#[must_use]
#[wasm_bindgen]
pub fn jotdown_parse(djot: &str) -> String {
jotdown::Parser::new(djot)
.map(|e| format!("{:?}\n", e))
.collect()
}