dioxus_tw_components/components/molecules/markdown/
props.rs1use crate::attributes::*;
2use dioxus::prelude::*;
3use dioxus_tw_components_macro::UiComp;
4
5#[derive(Clone, Default, PartialEq, Props, UiComp)]
6pub struct MarkdownProps {
7 #[props(extends = GlobalAttributes)]
8 attributes: Vec<Attribute>,
9 #[props(into, default = String::new())]
13 pub content: String,
14}
15
16pub fn Markdown(mut props: MarkdownProps) -> Element {
18 props.update_class_attribute();
19 let content = stringToHTML(props.content.clone());
20 rsx! {
21 div {
22 dangerous_inner_html: "{content}",
23 ..props.attributes,
24 }
25 }
26}
27
28fn stringToHTML(content: String) -> String {
32 use pulldown_cmark::{Options, Parser, html};
33
34 let mut options = Options::empty();
35 options.insert(Options::ENABLE_TABLES);
36 options.insert(Options::ENABLE_FOOTNOTES);
37 options.insert(Options::ENABLE_STRIKETHROUGH);
38 options.insert(Options::ENABLE_TASKLISTS);
39 options.insert(Options::ENABLE_SMART_PUNCTUATION);
40
41 let parser = Parser::new_ext(&content, options);
42
43 let mut html_output = String::new();
44 html::push_html(&mut html_output, parser);
45
46 html_output
47}