| Crates.io | markdown_view_leptos |
| lib.rs | markdown_view_leptos |
| version | 0.1.0 |
| created_at | 2025-09-01 02:43:54.67972+00 |
| updated_at | 2025-09-01 02:43:54.67972+00 |
| description | Render Markdown with embedded Leptos components via a simple macro (MDX-like for Leptos). |
| homepage | |
| repository | https://github.com/victorfds/markdown_view_leptos |
| max_upload_size | |
| id | 1819067 |
| size | 59,871 |
Compile-time Markdown to Leptos view! with MDX‑like inline components.
{{ <MyComp prop=value/> }}file = "...", or url = "..." sources{{ ... }} inside triple‑backtick code blocksSecurity note: the generated HTML is injected via
inner_html. Only use trusted Markdown or sanitize upstream.
cargo add markdown_view_leptos
For CSR (WASM):
rustup target add wasm32-unknown-unknowncargo install trunk)use leptos::prelude::*;
use markdown_view_leptos::markdown_view;
#[component]
fn Hello() -> impl IntoView {
view! { <em>"Hello from a component"</em> }
}
#[component]
pub fn App() -> impl IntoView {
// Embed a real component inside Markdown using {{ <Hello/> }}
let md = r#"
# Title
Some text before the component.
{{ <Hello/> }}
And some text after.
"#;
view! { <main>{markdown_view!(md)}</main> }
}
file paths are resolved relative to your crate root (CARGO_MANIFEST_DIR).
Below is a live Leptos component:
use leptos::prelude::*;
use markdown_view_leptos::markdown_view;
#[component]
pub fn App() -> impl IntoView {
view! { <section>{markdown_view!(file = "content.md")}</section> }
}
When using file = "...", the macro emits an include_str! so edits to the file trigger recompiles.
use leptos::prelude::*;
use markdown_view_leptos::markdown_view;
#[component]
pub fn App() -> impl IntoView {
view! {
<div>{markdown_view!(url = "https://github.com/leptos-rs/awesome-leptos/blob/main/README.md")}</div>
}
}
file = "..." for reproducible builds.pulldown‑cmark (tables, footnotes, strikethrough, task lists). Injected via inner_html into a view! tree.{{ ... }} outside fenced code blocks is parsed as Rust/RSX and spliced into the view! tree. The snippet must be valid in scope (e.g., <MyComp/>).{{ ... }} inside them is ignored and rendered literally.{{ ... }} doesn’t parse, it is rendered as plain Markdown so your build doesn’t fail unexpectedly.This repo includes a CSR example (Trunk):
examples/markdown-csr-example: Renders a canvas‑based ParticleText component from within Markdown.Run with Trunk:
cd examples/markdown-csr-example
trunk serve --open
{{ ... }} must be in scope where you invoke the macro.file = "..." uses include_str! to make the file a build input; saving it triggers a rebuild.cargo testcargo clippy --all-targets -- -D warnings and cargo fmt --allThank you for reading this 💙