This repository provides markdown rendering libraries for multiple Rust web frameworks (Yew, Dioxus, Leptos). It follows a workspace structure with a core library and framework-specific implementations.
This is a Cargo workspace containing:
web-markdown/- Core library providing the abstract markdown rendering APIyew-markdown/- Yew framework implementationdioxus-markdown/- Dioxus framework implementationleptos-markdown/- Leptos framework implementationexamples/- Example applications for each framework (in framework-specific directories)
# 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# Add WASM target if not present
rustup target add wasm32-unknown-unknown
# Build for WASM
cargo build --target wasm32-unknown-unknown# 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 serveThe web-markdown crate defines:
Contexttrait - Abstract interface for framework-specific renderingmarkdown_component()function - Main entry point for parsing markdownHtmlElementenum - HTML element abstractionsMdComponentPropsstruct - Props for custom components
Each framework (Yew, Dioxus, Leptos) implements the Context trait by:
- Creating framework-specific component props structs
- Implementing
Contextfor a reference to those props - Mapping
HtmlElementenum to framework HTML elements - Providing a main component (e.g.,
Markdownfor Yew)
Each framework supports custom components via:
CustomComponentsstruct for registration- Component functions taking
MdComponentProps<V> - Registration via
register()method
- Use
cargo fmtfor formatting (enforced by CI) - Edition 2021
- Feature flags:
maths(default),debug - WASM compilation support required
- Follow existing patterns when adding new framework support
- Use framework-specific HTML macros (
html!for Yew,view!for Dioxus, etc.) - Implement all
Contexttrait methods - Support the same feature flags across frameworks
- Use
ComponentCreationErrorfor custom component errors - Use
Result<T, ComponentCreationError>return types - Convert any error type to
ComponentCreationErrorviaFromtrait
- Checks workflow: Runs
cargo check --all-featuresandcargo fmt -- --check - Build workflow: Builds examples with Trunk and deploys to GitHub Pages
- Target:
wasm32-unknown-unknownrequired for all checks
# Run CI checks locally
cargo check --all-features
cargo fmt -- --check
# Test examples
cd yew-markdown/examples/showcase && trunk buildpulldown-cmark- Markdown parsingsyntect- Syntax highlightingweb-sys- Web APIskatex-rs- Math rendering (optional, feature-gated)
yew = "0.21"for Yew implementation- Dioxus and Leptos versions in their respective Cargo.toml files
- All code must compile for
wasm32-unknown-unknowntarget - Use conditional compilation
#[cfg(target_arch = "wasm32")]when needed - Trunk is required for building examples
maths(default): Enables KaTeX math renderingdebug: Enables debug information output- Always test with
--all-features
- Components must be registered before markdown rendering
- Use
BTreeMapinternally for component storage - Component names are static string references
- Requires external KaTeX CSS stylesheet
- Automatically injected when
mathsfeature is enabled - Uses
MATH_STYLE_SHEET_LINKconstant for CDN resource - Uses
katex-rscrate for WASM-compatible math rendering
- YAML-style metadata blocks are parsed
- Accessible via
frontmatterprop in framework components - Use
set_frontmatter()method inContextimplementation
- Always run
cargo fmtbefore committing - This is enforced by CI and required for all PRs - Use
cargo fmt -- --checkto verify formatting without making changes - CI will fail if code is not properly formatted
- Run
cargo fmtto format all code - Run
cargo check --all-featuresto ensure compilation - Test changes with relevant framework examples
- Verify WASM compilation:
cargo build --target wasm32-unknown-unknown
- Changes to core library: Test with all framework implementations
- Framework-specific changes: Only test that framework's examples
- New features: Add to core library first, then implement in frameworks
- Examples: Use Trunk for development and deployment
- Always run:
cargo fmtbefore committing (enforced by CI)
- Create new crate in workspace with appropriate dependencies
- Implement
Contexttrait for framework's component props - Map all
HtmlElementvariants to framework HTML - Create main component following existing patterns
- Add example application with common functionality
- Update workspace Cargo.toml to include new member
- Add to CI matrix if needed