### 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) content content ## Invalid (will be treated as HTML)
standard html
standard html no 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! {