jotdown_wasm: add events with spans format
This commit is contained in:
parent
79b5119209
commit
2a3973674f
2 changed files with 15 additions and 5 deletions
|
@ -21,7 +21,10 @@
|
||||||
output.innerText = jotdown_render(input.innerText);
|
output.innerText = jotdown_render(input.innerText);
|
||||||
} else if (fmt.value == "events") {
|
} else if (fmt.value == "events") {
|
||||||
output.classList.add("verbatim")
|
output.classList.add("verbatim")
|
||||||
output.innerText = jotdown_parse(input.innerText);
|
output.innerText = jotdown_parse(input.innerText, false);
|
||||||
|
} else if (fmt.value == "events_spans") {
|
||||||
|
output.classList.add("verbatim")
|
||||||
|
output.innerText = jotdown_parse(input.innerText, true);
|
||||||
} else if (fmt.value == "events_indent") {
|
} else if (fmt.value == "events_indent") {
|
||||||
output.classList.add("verbatim")
|
output.classList.add("verbatim")
|
||||||
output.innerText = jotdown_parse_indent(input.innerText);
|
output.innerText = jotdown_parse_indent(input.innerText);
|
||||||
|
@ -50,6 +53,7 @@
|
||||||
<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>
|
<option value="events">events</option>
|
||||||
|
<option value="events_spans">events (with offsets)</option>
|
||||||
<option value="events_indent">events (indented)</option>
|
<option value="events_indent">events (indented)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,10 +22,16 @@ pub fn jotdown_render(djot: &str) -> String {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn jotdown_parse(djot: &str) -> String {
|
pub fn jotdown_parse(djot: &str, spans: bool) -> String {
|
||||||
jotdown::Parser::new(djot)
|
let mut out = String::new();
|
||||||
.map(|e| format!("{:?}\n", e))
|
for (e, sp) in jotdown::Parser::new(djot).into_offset_iter() {
|
||||||
.collect()
|
write!(out, "{:?}", e).unwrap();
|
||||||
|
if spans {
|
||||||
|
write!(out, " {:?} {:?}", &djot[sp.clone()], sp).unwrap();
|
||||||
|
}
|
||||||
|
writeln!(out).unwrap();
|
||||||
|
}
|
||||||
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
Loading…
Reference in a new issue