Skip to content

Commit

Permalink
PR #39 add source map
Browse files Browse the repository at this point in the history
Merge branch 'spans2'
  • Loading branch information
hellux committed May 15, 2023
2 parents 8be7c4c + bbdb314 commit 70303e7
Show file tree
Hide file tree
Showing 12 changed files with 1,644 additions and 1,201 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ jobs:
matrix:
target:
- parse
- parse_balance
- html
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 5 additions & 1 deletion examples/jotdown_wasm/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
output.innerText = jotdown_render(input.innerText);
} else if (fmt.value == "events") {
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") {
output.classList.add("verbatim")
output.innerText = jotdown_parse_indent(input.innerText);
Expand Down Expand Up @@ -50,6 +53,7 @@
<option value="preview">preview</option>
<option value="html">html</option>
<option value="events">events</option>
<option value="events_spans">events (with offsets)</option>
<option value="events_indent">events (indented)</option>
</select>
</div>
Expand Down
14 changes: 10 additions & 4 deletions examples/jotdown_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ pub fn jotdown_render(djot: &str) -> String {

#[must_use]
#[wasm_bindgen]
pub fn jotdown_parse(djot: &str) -> String {
jotdown::Parser::new(djot)
.map(|e| format!("{:?}\n", e))
.collect()
pub fn jotdown_parse(djot: &str, spans: bool) -> String {
let mut out = String::new();
for (e, sp) in jotdown::Parser::new(djot).into_offset_iter() {
write!(out, "{:?}", e).unwrap();
if spans {
write!(out, " {:?} {:?}", &djot[sp.clone()], sp).unwrap();
}
writeln!(out).unwrap();
}
out
}

#[must_use]
Expand Down
Loading

0 comments on commit 70303e7

Please sign in to comment.