rscx-mdx
Render Markdown into HTML, while having custom
RSCx components inside.
Usage
use rscx::{component, html, props};
use rscx_mdx::mdx::{Mdx, MdxComponentProps, MdxProps};
#[tokio::main]
async fn main() {
let source = r#"---
title: "Hello, world!"
---
# Hello, world!
This is a **markdown** file with some *content*, but also custom RSCx components!
<CustomTitle />
<Layout>
## subtitle
</Layout>
"#;
let res = html! {
<Mdx source=source handler=handle />
};
println!("{}", res);
}
async fn handle(name: String, props: MdxComponentProps) -> String {
match name.as_str() {
"CustomTitle" => html! {
<CustomTitle />
},
"Layout" => html! {
<Layout>
{props.children}
</Layout>
},
_ => String::new(),
}
}
#[component]
fn CustomTitle() -> String {
html! {
<h1>Some custom title!</h1>
}
}
#[props]
pub struct LayoutProps {
children: String,
}
#[component]
fn Layout(props: LayoutProps) -> String {
html! {
<div class="layout">
{props.children}
</div>
}
}