Skip to content

Commit

Permalink
added todo lists support and add it in showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
rambip committed Aug 2, 2023
1 parent d4ce696 commit ae7e001
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Wikilinks are supported to: [[https://en.wikipedia.org/wiki/Markdown|markdown]]
- and
- unorderded
- too
Even todo lists:
- [ ] todo
- [x] done
"#;

#[component]
Expand Down
28 changes: 23 additions & 5 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ impl<'a> Iterator for Renderer<'a>
SoftBreak => Ok(self.next()?),
HardBreak => Ok(view!{cx, <br/>}.into_any()),
Rule => Ok(render_rule(self.context, range)),
TaskListMarker(_) => HtmlError::err("do not support todo lists yet"),
TaskListMarker(m) => Ok(render_tasklist_marker(self.context, *m, range)),
Math(disp, content) => render_maths(self.context, &content, &disp, range),
};

Some(
rendered.unwrap_or_else(|e| view!{cx,
<div class="error">
<p>"got this error while rendering markdown"</p>
<span>{e.to_string()}</span>
</div>
<span class="error" style="border: 1px solid red">
{e.to_string()}
<br/>
</span>
}.into_any()
)
)
Expand Down Expand Up @@ -272,6 +272,24 @@ impl<'a> Renderer<'a>
}


fn render_tasklist_marker(context: &RenderContext, m: bool, position: Range<usize>)
-> Html {
let cx = context.cx;
let onclick = context.onclick.clone();
let callback = move |e: MouseEvent| {
e.prevent_default();
e.stop_propagation();
let click_event = MarkdownMouseEvent {
mouse_event: e,
position: position.clone()
};
onclick(click_event)
};
view!{
cx, <input type="checkbox" checked=m on:click=callback>
</input>
}.into_any()
}

fn render_rule(context: &RenderContext, range: Range<usize>) -> Html{
let cx = context.cx;
Expand Down

0 comments on commit ae7e001

Please sign in to comment.