### Trunk Development Commands
Source: https://github.com/rambip/rust-web-markdown/blob/main/AGENTS.md
Commands for installing Trunk and managing the lifecycle of example applications.
```bash
# Install trunk if not present
cargo install trunk
# Build example for deployment
cd yew-markdown/examples/showcase
trunk build --release --public-url /rust-web-markdown/showcase
# Serve example locally for development
trunk serve
```
--------------------------------
### Installation
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Instructions for adding the required dependencies to your Cargo.toml file.
```APIDOC
## Installation
### Yew
[dependencies]
yew-markdown = "0.1.0"
### Dioxus
[dependencies]
dioxus-markdown = "0.1.0"
### Leptos
[dependencies]
leptos-markdown = { git = "https://github.com/rambip/rust-web-markdown" }
```
--------------------------------
### Install leptos-markdown via Cargo.toml
Source: https://github.com/rambip/rust-web-markdown/blob/main/leptos-markdown/README.md
Add the crate as a git dependency in your Cargo.toml file.
```toml
# inside Cargo.toml
leptos-markdown = {git="https://github.com/rambip/rust-web-markdown"}
```
--------------------------------
### Install Crate Dependencies
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Add the required framework-specific crate to your Cargo.toml file.
```toml
# For Yew projects
[dependencies]
yew-markdown = "0.1.0"
# For Dioxus projects
[dependencies]
dioxus-markdown = "0.1.0"
# For Leptos projects (git dependency until published)
[dependencies]
leptos-markdown = { git = "https://github.com/rambip/rust-web-markdown" }
# Optional: Disable math rendering if not needed
[dependencies.yew-markdown]
version = "0.1.0"
default-features = false
```
--------------------------------
### Build and Test Commands
Source: https://github.com/rambip/rust-web-markdown/blob/main/AGENTS.md
Commands for verifying workspace compilation, formatting, and building framework-specific libraries or examples.
```bash
# Check all workspace members compile
cargo check --all-features
# Format code (required by CI)
cargo fmt
# Build specific framework library
cargo check -p yew-markdown
cargo check -p dioxus-markdown
cargo check -p leptos-markdown
# Build and run examples (requires Trunk)
cd yew-markdown/examples/showcase && trunk build
cd yew-markdown/examples/showcase && trunk serve
```
--------------------------------
### Local CI Testing Commands
Source: https://github.com/rambip/rust-web-markdown/blob/main/AGENTS.md
Commands to replicate CI checks and verify examples locally.
```bash
# Run CI checks locally
cargo check --all-features
cargo fmt -- --check
# Test examples
cd yew-markdown/examples/showcase && trunk build
```
--------------------------------
### Apply Custom Component Naming Conventions
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Custom components must start with an uppercase letter or contain a dash to avoid being treated as standard HTML elements.
```markdown
## Valid Custom Component Names
### Uppercase start (always treated as custom)
content
### Lowercase with dash (must contain at least one dash)
contentcontent
## Invalid (will be treated as HTML)
standard html
standard htmlno dash, lowercase - treated as HTML
```
--------------------------------
### WebAssembly Development Commands
Source: https://github.com/rambip/rust-web-markdown/blob/main/AGENTS.md
Commands to prepare the environment and build the project for the WebAssembly target.
```bash
# Add WASM target if not present
rustup target add wasm32-unknown-unknown
# Build for WASM
cargo build --target wasm32-unknown-unknown
```
--------------------------------
### Basic Markdown Rendering with Click Handling
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Renders markdown content and highlights the clicked section. Requires the `yew-markdown` crate.
```rust
let callback = ctx.link().callback(|x: MarkdownMouseEvent|
Msg::ShowSource(x.position)
);
```
```rust
use yew::prelude::*;
use yew_markdown::Markdown;
struct App {
start_index: usize,
end_index: usize,
}
enum Msg {
ShowSource(Range),
}
impl Component for App {
type Message = Msg;
type Properties = ();
fn create(_ctx: &Context) -> Self {
Self { start_index: 0, end_index: 0 }
}
fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool {
match msg {
Msg::ShowSource(range) => {
self.start_index = range.start;
self.end_index = range.end;
}
}
true
}
fn view(&self, ctx: &Context) -> Html {
let (before, x) = MARKDOWN_SOURCE.split_at(self.start_index);
let (middle, after) = x.split_at(self.end_index - self.start_index);
let callback = ctx.link()
.callback(|x: MarkdownMouseEvent| Msg::ShowSource(x.position));
html! {
{"markdown source:"}
{before}
{middle}
{after}
}
}
}
fn main() {
wasm_logger::init(wasm_logger::Config::default());
yew::Renderer::::new().render();
}
```
--------------------------------
### Add yew-markdown dependency
Source: https://github.com/rambip/rust-web-markdown/blob/main/yew-markdown/README.md
Include the library in your Cargo.toml file.
```toml
# Cargo.toml
yew-markdown = "0.0.1"
```
--------------------------------
### Implement Markdown Editor with Rendering Options
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Builds a Yew component that renders markdown with configurable settings like hard line breaks.
```rust
use yew::prelude::*;
use yew_markdown::Markdown;
struct App {
content: String,
hard_line_breaks: bool,
debug_info: Vec,
}
enum Msg {
UpdateContent(String),
UpdateDebugInfo(Vec),
SetHardLineBreaks(bool),
}
impl Component for App {
type Message = Msg;
type Properties = ();
fn create(_ctx: &Context) -> Self {
Self {
content: String::new(),
hard_line_breaks: false,
debug_info: Vec::new(),
}
}
fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool {
match msg {
Msg::SetHardLineBreaks(b) => self.hard_line_breaks = b,
Msg::UpdateContent(s) => self.content = s,
Msg::UpdateDebugInfo(s) => {
let need_render = self.debug_info != s;
self.debug_info = s;
return need_render;
}
}
true
}
fn view(&self, ctx: &Context) -> Html {
let oninput = ctx.link().callback(Msg::UpdateContent);
let send_debug_info = ctx.link().callback(Msg::UpdateDebugInfo);
html! {
}
}
}
```
--------------------------------
### Registering Custom Dioxus Components in Markdown
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Shows how to register custom components in Dioxus for markdown rendering. Supports attribute parsing and document modification. Requires `dioxus-markdown` and `dioxus` crates.
```rust
use dioxus::prelude::*;
use dioxus_markdown::*;
static MARKDOWN_SOURCE: &str = r#"
## Here is a counter:
An invalid counter:
A defaulted counter:
A counter which modifies the document:
"#;
#[derive(Props)]
struct EphemeralCounterProps {
initial: Option,
}
fn EphemeralCounter(props: EphemeralCounterProps) -> Element {
let count = use_state(move || props.initial.unwrap_or(0));
rsx! {
button { onclick: move |_| count.set(*count - 1), "-"}
{*count}
button { onclick: move |_| count.set(*count + 1), "+"}
}
}
#[derive(Props)]
struct PersistedCounterProps {
value: i32,
}
fn PersistedCounter(props: PersistedCounterProps) -> Element {
let count = use_state(move || props.value);
let document = use_document();
use_effect(move || {
document.set_title(&format!("Counter: {}", *count));
});
rsx! {
button { onclick: move |_| count.set(*count - 1), "-"}
{*count}
button { onclick: move |_| count.set(*count + 1), "+"}
}
}
#[component]
fn App() -> Element {
let mut components = CustomComponents::new();
components.register("EphemeralCounter", |p| {
Ok(rsx! {
})
});
components.register("PersistedCounter", |p| {
Ok(rsx! {
})
});
rsx! {
article {
h1 {"The source"}
Markdown { src: format!("`{}`", MARKDOWN_SOURCE) }
h1 {"The result"}
Markdown { src: MARKDOWN_SOURCE, components: components }
}
}
}
fn main() {
dioxus_logger::init(dioxus_logger::Config::default());
LaunchBuilder::new().launch(App);
}
```
--------------------------------
### Render basic markdown
Source: https://github.com/rambip/rust-web-markdown/blob/main/yew-markdown/README.md
Use the Markdown component within a Yew html! macro to render markdown strings.
```rust
use yew_markdown::Markdown;
...
html!{
}
```
--------------------------------
### Render Markdown in Leptos
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Use Leptos view syntax to render static or reactive markdown content.
```rust
use leptos::*;
use leptos_markdown::Markdown;
// Static markdown rendering
#[component]
fn StaticMarkdown() -> impl IntoView {
view! {
}
}
// Dynamic markdown with reactive signals
#[component]
fn DynamicMarkdown() -> impl IntoView {
let (content, set_content) = create_signal("# Markdown Power !".to_string());
view! {
}
}
// With wikilinks enabled
#[component]
fn App() -> impl IntoView {
view! {
}
}
fn main() {
console_error_panic_hook::set_once();
mount_to_body(App)
}
```
--------------------------------
### Render basic markdown
Source: https://github.com/rambip/rust-web-markdown/blob/main/dioxus-markdown/README.md
Use the Markdown component within your rsx! macro to render markdown strings.
```rust
use dioxus_markdown::Markdown;
...
rsx!{
Markdown {src:"# Mardown power !"}
}
```
--------------------------------
### Custom Component Naming Rules
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Guidelines for naming custom components to ensure they are correctly identified by the parser.
```APIDOC
## Custom Component Naming
### Description
Rules to distinguish custom interactive components from standard HTML elements.
### Rules
- **Uppercase start**: Any component starting with an uppercase letter is treated as a custom component (e.g., ).
- **Lowercase with dash**: Any lowercase component name containing at least one dash is treated as a custom component (e.g., ).
- **Standard HTML**: Components that are lowercase and contain no dashes are treated as standard HTML elements (e.g.,
, ).
```
--------------------------------
### Add dependency to Cargo.toml
Source: https://github.com/rambip/rust-web-markdown/blob/main/dioxus-markdown/README.md
Include the library in your project by adding this entry to your Cargo.toml file.
```toml
# Cargo.toml
dioxus-markdown = "0.1.0"
```
--------------------------------
### Render Markdown in Dioxus
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Use the rsx! macro to render markdown, with optional support for wikilinks.
```rust
use dioxus::prelude::*;
use dioxus_markdown::Markdown;
static MARKDOWN_SOURCE: &str = r#"
## Code
```rust
fn main() {
println!("hello world !")
}
```
## Math
- $1+1=2$
- $e^{i\pi}+1=0$
$$\int_0^{+\infty}\dfrac{\sin(t)}{t}\,dt=\dfrac{\sqrt{\pi}}{2}$$
## Links and images

Wikilinks are supported too: [[https://en.wikipedia.org/wiki/Markdown|markdown]]
## Style
| unstyled | styled |
| :-----: | ------ |
| bold | **bold** |
| italics | *italics* |
> Hey, I am a quote !
## Lists
1) one
2) two
3) three
- [ ] todo
- [x] done
"#;
#[component]
fn App() -> Element {
rsx! {
Markdown { src: MARKDOWN_SOURCE, wikilinks: true }
}
}
fn main() {
dioxus::launch(App);
}
```
--------------------------------
### Render dynamic markdown in Leptos
Source: https://github.com/rambip/rust-web-markdown/blob/main/leptos-markdown/README.md
Pass a signal to the Markdown component to update rendered content reactively.
```rust
{
...
let (content, set_content) = create_signal("# Markdown Power !".to_string());
view!{
}
}
```
--------------------------------
### Render Markdown in Yew
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Use the Markdown component with a static source string to render content in a Yew application.
```rust
use yew::prelude::*;
use yew_markdown::Markdown;
static MARKDOWN_SOURCE: &str = r#"
## Code
```rust
fn main() {
println!("hello world !")
}
```
## Math
- $1+1=2$
- $e^{i\pi}+1=0$
$$\int_0^{+\infty}\dfrac{\sin(t)}{t}\,dt=\dfrac{\sqrt{\pi}}{2}$$
## Links and images

for markdown documentation, see [here](https://commonmark.org/help/)
## Style
| unstyled | styled |
| :-----: | ------ |
| bold | **bold** |
| italics | *italics* |
| strike | ~strike~ |
> Hey, I am a quote !
"#;
#[function_component(App)]
fn app() -> Html {
html! {
}
}
fn main() {
yew::Renderer::::new().render();
}
```
--------------------------------
### Render static markdown in Leptos
Source: https://github.com/rambip/rust-web-markdown/blob/main/leptos-markdown/README.md
Use the Markdown component to render static strings within a view.
```rust
use leptos::*;
use leptos_markdown::Markdown;
{
...
view!{
}
}
```
--------------------------------
### Component Props Reference
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Defines the properties available for configuring Markdown rendering in Yew and Dioxus components.
```APIDOC
## Component Properties
### Description
Configuration properties for the Markdown component, supporting customization of rendering, syntax highlighting, and interactive features.
### Properties
- **src** (AttrValue) - Required - The markdown source string to render.
- **onclick** (Callback) - Optional - Callback fired when any markdown element is clicked.
- **render_links** (Callback, Html>) - Optional - Custom link rendering callback.
- **theme** (&'static str) - Optional - Syntax highlighting theme name.
- **wikilinks** (bool) - Optional - Enable wikilinks support (e.g., [[link]]).
- **hard_line_breaks** (bool) - Optional - Convert soft breaks to hard breaks ( ).
- **parse_options** (Options) - Optional - Custom pulldown-cmark parsing options.
- **components** (CustomComponents) - Optional - Custom components registry for embedding interactive elements.
- **frontmatter** (UseStateHandle) - Optional - Signal to receive YAML frontmatter.
- **send_debug_info** (Callback>) - Optional - Debug callback for syntax tree info.
- **preserve_html** (bool) - Optional (Dioxus only) - Whether to preserve arbitrary HTML in markdown.
```
--------------------------------
### Define Component Properties for Yew and Dioxus
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Use these structs to configure markdown rendering behavior, including syntax highlighting, wikilinks, and custom component registries.
```rust
// Yew Props
#[derive(PartialEq, Properties, Clone)]
pub struct Props {
// Required: The markdown source string to render
pub src: AttrValue,
// Optional: Callback fired when any markdown element is clicked
// Provides MarkdownMouseEvent with position range in source
pub onclick: Option>,
// Optional: Custom link rendering callback
// Use to override default link/image rendering
pub render_links: Option, Html>>,
// Optional: Syntax highlighting theme name
// Supports default syntect themes
pub theme: Option<&'static str>,
// Enable wikilinks support: [[link]] or [[url|name]]
#[prop_or(false)]
pub wikilinks: bool,
// Convert soft breaks (single newlines) to hard breaks ( )
#[prop_or(false)]
pub hard_line_breaks: bool,
// Custom pulldown-cmark parsing options
pub parse_options: Option,
// Custom components registry for embedding interactive elements
pub components: CustomComponents,
// Signal to receive YAML frontmatter if present
pub frontmatter: Option>,
// Debug callback to receive parsed syntax tree info
pub send_debug_info: Option>>,
}
// Dioxus additional prop
#[derive(Props)]
pub struct MdProps {
// ... same as above, plus:
// Whether to preserve arbitrary HTML in markdown (security consideration)
// If true, content may inject unsafe HTML
#[props(default = true)]
preserve_html: bool,
}
```
--------------------------------
### Handle Interactive Click Events in Yew
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Capture click events on markdown elements to retrieve source positions for features like highlighting.
```rust
use yew::prelude::*;
use yew_markdown::{Markdown, MarkdownMouseEvent};
use core::ops::Range;
static MARKDOWN_SOURCE: &str = r#"
# Interactive markdown experiment
## Goal
Click on any text on this page and it will appear highlighted in the source
```
--------------------------------
### Access Markdown Component Properties
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Demonstrates how to retrieve attributes and children from markdown components using the MdComponentProps API.
```rust
use yew_markdown::MdComponentProps;
// Given markdown: **content**
fn handle_component(props: MdComponentProps) -> Result {
// Get raw attribute value as Option
let color: Option = props.get("color");
// Returns: Some("blue")
// Get attribute with automatic parsing, returns error if missing
let size: i32 = props.get_parsed("size")?;
// Returns: Ok(5) or Err("please provide the attribute `size`")
// Get optional parsed attribute, returns None if missing
let width: Option = props.get_parsed_optional("width")?;
// Returns: Ok(None) if missing, Ok(Some(value)) if present, Err if parse fails
// Get attribute with range information for source location
let attr = props.get_attribute("color");
// Returns MdComponentAttribute { value: "blue", range: 15..19 }
// Access the rendered children (inner markdown content)
let children = props.children;
// Contains the rendered **content** as Html/Element/View
Ok(html! {
{children}
})
}
```
--------------------------------
### Registering Custom Yew Components in Markdown
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Embeds custom Yew components within markdown. Requires `yew-markdown` and `yew` crates. Custom components can accept parsed attributes and children.
```rust
use yew::prelude::*;
use yew_markdown::{CustomComponents, Markdown};
static MARKDOWN_SOURCE: &str = r#"
## Here are a few counters:
## Here is a Box:
**I am in a blue box !**
"#;
#[derive(PartialEq, Properties)]
struct CounterProps {
initial: Option,
}
#[function_component]
fn Counter(props: &CounterProps) -> Html {
let count = use_state(move || props.initial.unwrap_or(0));
let increment = {
let count = count.clone();
Callback::from(move |_| count.set(*count + 1))
};
let decrement = {
let count = count.clone();
Callback::from(move |_| count.set(*count - 1))
};
html! {
}
}
#[function_component(App)]
fn app() -> Html {
let mut components = CustomComponents::new();
// Register a Counter component with optional parsed attributes
components.register("Counter", |p| {
Ok(html! {
})
});
// Register a custom-box component with children
components.register("custom-box", |p| {
Ok(html! {{p.children}})
});
html! {
{"The source"}
{"The result"}
}
}
fn main() {
wasm_logger::init(wasm_logger::Config::default());
yew::Renderer::::new().render();
}
```
--------------------------------
### Define Custom Markdown Components in Dioxus
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Defines functional components and registers them with a CustomComponents instance to be used within markdown.
```rust
#[component]
fn EphemeralCounter(initial: i32) -> Element {
let mut count = use_signal(|| initial);
rsx! {
div {
button { onclick: move |_| count -= 1, "-" }
"{count}"
button { onclick: move |_| count += 1, "+" }
}
}
}
#[component]
fn PersistedCounter(mut count: ReadWriteBox) -> Element {
let mut count2 = count.clone();
rsx! {
div {
button { onclick: move |_| count -= 1, "-" }
"{count}"
button { onclick: move |_| count2 += 1, "+" }
}
}
}
#[component]
fn ColorBox(children: Element) -> Element {
rsx! {
div { style: "border: 2px solid blue", {children} }
}
}
#[component]
fn App() -> Element {
let mut components = CustomComponents::new();
let src = use_signal(|| MARKDOWN_SOURCE.to_string());
// Register component with optional parsed attribute
components.register("EphemeralCounter", |props| {
Ok(rsx! {
EphemeralCounter { initial: props.get_parsed_optional("initial")?.unwrap_or(0) }
})
});
// Register component that can modify the source document
components.register("PersistedCounter", move |props| {
let value = props.get_attribute("value").unwrap();
let count = ReadWriteBox::from_sub_string(src, value.range)?;
Ok(rsx! {
PersistedCounter { count }
})
});
// Register component with children
components.register("custom-box", |props| {
let children = props.children;
Ok(rsx! {
ColorBox { children }
})
});
rsx! {
h1 { "Source" }
Markdown { src: "```md\n{src}\n```" }
h1 { "Result" }
Markdown { src: src, components }
}
}
fn main() {
dioxus::launch(App);
}
```
--------------------------------
### MdComponentProps API
Source: https://context7.com/rambip/rust-web-markdown/llms.txt
Methods for accessing attributes and children within a custom markdown component.
```APIDOC
## MdComponentProps API
### Description
The `MdComponentProps` struct provides methods to access custom component attributes and children from markdown.
### Methods
- **get(key: &str)**: Returns the raw attribute value as `Option`.
- **get_parsed(key: &str)**: Returns the attribute value parsed into a type, or an error if missing.
- **get_parsed_optional(key: &str)**: Returns the attribute value parsed into a type, or `None` if missing.
- **get_attribute(key: &str)**: Returns the `MdComponentAttribute` containing value and range information.
- **children**: Accesses the rendered inner markdown content.
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.