Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Pitasi/rscx-mdx
Supercharge your markdown including RSCx components.
https://github.com/Pitasi/rscx-mdx
Last synced: about 2 months ago
JSON representation
Supercharge your markdown including RSCx components.
- Host: GitHub
- URL: https://github.com/Pitasi/rscx-mdx
- Owner: Pitasi
- Created: 2023-09-07T17:35:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-15T20:47:48.000Z (11 months ago)
- Last Synced: 2024-10-30T14:49:28.851Z (2 months ago)
- Language: Rust
- Size: 11.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rscx-mdx
Render Markdown into HTML, while having custom
[RSCx](https://github.com/Pitasi/rscx) components inside.## Usage
```rust
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!
## subtitle
"#;
let res = html! {
};println!("{}", res);
// output ->
//
//Hello, world!
//This is a markdown file with some content, but also custom RSCx components!
//Some custom title!
//
//subtitle
//
}/// handle is called everytime a custom component is encountered.
/// The props are standardized in the MdxComponentProps struct and can be later parsed and used
/// to render the component.
async fn handle(name: String, props: MdxComponentProps) -> String {
match name.as_str() {
"CustomTitle" => html! {
},
"Layout" => html! {
{props.children}
},
_ => String::new(),
}
}// below we define some custom components that can be used in the markdown file
#[component]
fn CustomTitle() -> String {
html! {
Some custom title!
}
}#[props]
pub struct LayoutProps {
children: String,
}#[component]
fn Layout(props: LayoutProps) -> String {
html! {
{props.children}
}
}
```