Skip to content

Commit

Permalink
use latest api with better inner_html
Browse files Browse the repository at this point in the history
  • Loading branch information
rambip committed Nov 29, 2023
1 parent 37acae6 commit c71b5fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

23 changes: 16 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rust_web_markdown::{
render_markdown, ElementAttributes, HtmlElement, MarkdownProps, Context,
CowStr, MouseEvent
CowStr,
};

use core::ops::Range;
Expand All @@ -13,7 +13,7 @@ use yew::prelude::{
function_component, html, AttrValue, Callback, Html, Properties, UseStateHandle,
};

use web_sys::window;
use web_sys::{window, MouseEvent};

use std::collections::HashMap;

Expand All @@ -39,6 +39,8 @@ impl<'a> Context<'a, 'static> for &'a Props {

type Setter<T: 'static> = UseStateHandle<T>;

type MouseEvent = MouseEvent;

fn props(self) -> MarkdownProps<'a, 'static, Self> {
let Props {
render_links,
Expand Down Expand Up @@ -82,11 +84,6 @@ impl<'a> Context<'a, 'static> for &'a Props {
let classes: Vec<_> = attributes.classes.iter().map(|x| x.to_string()).collect();
let on_click = attributes.on_click;

let inside = match attributes.inner_html {
Some(i) => Html::from_html_unchecked(i.to_string().into()),
None => inside
};

match e {
HtmlElement::Div => {
html! {<div style={style} onclick={on_click} class={classes}>{inside}</div>}
Expand Down Expand Up @@ -158,6 +155,18 @@ impl<'a> Context<'a, 'static> for &'a Props {
}
}

fn el_span_with_inner_html(self, inner_html: String, attributes: ElementAttributes<Callback<MouseEvent>>) -> Self::View {
let style = attributes.style.map(|x| x.to_string());
let classes: Vec<_> = attributes.classes.iter().map(|x| x.to_string()).collect();
let onclick = attributes.on_click;

html! {
<span style={style} onclick={onclick} class={classes}>
{Html::from_html_unchecked(inner_html.into())}
</span>
}
}

fn el_hr(self, attributes: ElementAttributes<Callback<MouseEvent>>) -> Self::View {
let style = attributes.style.map(|x| x.to_string());
let classes: Vec<_> = attributes.classes.iter().map(|x| x.to_string()).collect();
Expand Down

0 comments on commit c71b5fa

Please sign in to comment.