### Miri Setup and Test Execution Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Sets up and runs Miri for detecting undefined behavior. Requires the nightly toolchain. ```bash cargo +nightly miri setup ``` ```bash cargo +nightly miri test --tests --no-default-features --all-features ``` -------------------------------- ### Docs.rs Compatibility Check Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Checks compatibility with Docs.rs for the specified crate. Requires `docs-rs` to be installed. ```bash cargo docs-rs -p hypertext ``` -------------------------------- ### Check With All Features Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Checks the workspace with all available features enabled. ```bash cargo check --workspace --all-targets --all-features ``` -------------------------------- ### Run Main Integration Test Suite Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Runs the main integration test suite, mimicking the CI matrix. ```bash cargo test --tests --no-default-features ``` ```bash cargo test --tests --no-default-features --features default ``` ```bash cargo test --tests --no-default-features --all-features ``` -------------------------------- ### Apply Formatting Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Applies the project's formatting rules to all files. Requires the nightly toolchain due to unstable `rustfmt.toml` options. ```bash cargo +nightly fmt --all ``` -------------------------------- ### Run Docs Tests Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Runs documentation tests, replicating CI behavior. ```bash cargo test --doc --all-features ``` -------------------------------- ### Run Single Integration Test File Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Executes all tests within a specified integration test file. ```bash cargo test -p hypertext --test components --features default ``` -------------------------------- ### CI-Compatible Clippy Matrix Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Runs Clippy with different feature combinations to match CI behavior. ```bash cargo clippy --no-default-features ``` ```bash cargo clippy --no-default-features --features default ``` ```bash cargo clippy --no-default-features --all-features ``` -------------------------------- ### Web Framework Integration with Axum Source: https://context7.com/vidhanio/hypertext/llms.txt Hypertext provides Responder/IntoResponse implementations for Lazy and Rendered across major frameworks. Enable the corresponding Cargo feature. ```toml # Cargo.toml [dependencies] # Pick one (or more): hypertext = { version = "0.12", features = ["axum"] } # hypertext = { version = "0.12", features = ["actix-web"] } # hypertext = { version = "0.12", features = ["rocket"] } # hypertext = { version = "0.12", features = ["poem"] } ``` ```rust // Axum example (feature = "axum") // Lazy and Rendered both implement axum's IntoResponse, // returning Content-Type: text/html; charset=utf-8 automatically. use hypertext::prelude::*; // use axum::{Router, routing::get}; async fn index_handler() -> impl /* axum_core::response:: */ IntoResponse { maud! { !DOCTYPE html { head { title { "Home" } } body { h1 { "Welcome!" } } } } // No .render() needed — Lazy implements IntoResponse directly } // In Actix-Web (feature = "actix-web"): // Lazy implements actix_web::Responder // async fn index(req: HttpRequest) -> impl Responder { maud! { ... } } // In Rocket (feature = "rocket"): // Lazy implements rocket::response::Responder // #[get("/")] fn index() -> impl Responder { maud! { ... } } ``` -------------------------------- ### Build Components with `#[derive(Builder)]` Source: https://context7.com/vidhanio/hypertext/llms.txt Combine `#[derive(Builder, Renderable)]` on a struct to create components that use the builder pattern for property construction. `Option` fields are automatically optional in the component syntax. ```rust use hypertext::{Builder, prelude::*}; #[derive(Builder, Renderable)] #[maud( div { h1 { (self.title) } @if let Some(sub) = &self.subtitle { h2 { (sub) } } } )] struct Header { title: String, subtitle: Option, // automatically optional in component syntax } let result = maud! { Header title=("Hello".into()); Header title=("Hello".into()) subtitle=("World".into()); }.render(); assert_eq!( result.as_inner(), "

Hello

Hello

World

" ); ``` -------------------------------- ### Display and Debug Rendering with Escaping Source: https://context7.com/vidhanio/hypertext/llms.txt Use `%(expr)` for Display rendering and `?(expr)` for Debug rendering. Both automatically escape HTML. ```Rust use hypertext::prelude::*; #[derive(Debug)] struct Item { name: &'static str } impl std::fmt::Display for Item { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "", self.name) } } let item = Item { name: "widget" }; // %(expr) uses Display with escaping let display_result = maud! { p { %(item) } }.render(); assert_eq!(display_result.as_inner(), "

<Item: widget>

"); // ?(expr) uses Debug with escaping let debug_result = maud! { p { ?(item) } }.render(); assert_eq!(debug_result.as_inner(), r###"

Item { name: \"widget\" }

"###); ``` -------------------------------- ### Check Formatting Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Checks if the code adheres to the project's formatting rules, as defined in `rustfmt.toml`. Requires the nightly toolchain. ```bash cargo +nightly fmt --all --check ``` -------------------------------- ### Run All Tests Locally Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Runs all tests across the workspace with all features enabled for local convenience. ```bash cargo test --workspace --all-targets --all-features ``` -------------------------------- ### Render and Memoize Components with `RenderableExt` Source: https://context7.com/vidhanio/hypertext/llms.txt The `RenderableExt` trait provides `.render()` to produce a `Rendered` and `.memoize()` to pre-render and cache output as `Raw` for efficient re-use. ```rust use hypertext::prelude::*; // .render() — produces a Rendered let rendered = maud! { h1 { "Hello" } }.render(); assert_eq!(rendered.as_inner(), "

Hello

"); // .memoize() — pre-renders to Raw for embedding multiple times let nav = maud! { nav { a href="/" { "Home" } a href="/about" { "About" } } }.memoize(); let page1 = maud! { div { (nav) p { "Page 1" } } }.render(); let page2 = maud! { div { (nav) p { "Page 2" } } }.render(); assert_eq!(page1.as_inner(), r###"

Page 1

"###); assert_eq!(page2.as_inner(), r###"

Page 2

"###); ``` -------------------------------- ### Generate HTML with RSX Macro Source: https://github.com/vidhanio/hypertext/blob/main/README.md The `rsx!` macro provides an alternative syntax for generating HTML. It requires importing `hypertext::prelude::*`. This macro is suitable for creating dynamic HTML content. ```rust let shopping_list_rsx = rsx! {

Shopping List

    @for (i, item) in (1..).zip(shopping_list) {
  • }
} .render(); ``` -------------------------------- ### Quick Workspace Check Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Performs a quick check of the entire workspace, including all targets. ```bash cargo check --workspace --all-targets ``` -------------------------------- ### MathML Markup with `mathml::maud!` and `mathml::rsx!` Source: https://context7.com/vidhanio/hypertext/llms.txt Macros for generating MathML, validating against `hypertext_mathml_elements` and emitting self-closing tags for childless elements. ```Rust use hypertext::prelude::*; let maud_result = mathml::maud! { math display="block" { mfrac { mrow { mn { "1" } mo { "+" } mn { "2" } } mn { "3" } } } }.render(); let rsx_result = mathml::rsx! { 1+2 3 }.render(); assert_eq!(maud_result.as_inner(), rsx_result.as_inner()); assert_eq!( maud_result.as_inner(), "1+23" ); ``` -------------------------------- ### Dependency and License Audit Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Checks for potential issues with dependencies and licenses using `cargo deny`. ```bash cargo deny check ``` -------------------------------- ### List Available Tests Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Lists all available tests within a specified test file without running them. ```bash cargo test -p hypertext --test components --features default -- --list ``` -------------------------------- ### Run Single Test Function Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Executes a specific test function within a single integration test file, with exact name matching. ```bash cargo test -p hypertext --test components renderable_custom_name --features default -- --exact ``` -------------------------------- ### Workspace Linting with Clippy Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Runs Clippy across the entire workspace with all features enabled, treating warnings as errors. ```bash cargo clippy --workspace --all-targets --all-features -- -D warnings ``` -------------------------------- ### Generate HTML with Maud Macro Source: https://github.com/vidhanio/hypertext/blob/main/README.md Use the `maud!` macro to generate HTML structures. Ensure `hypertext::prelude::*` is imported. This macro allows for dynamic content generation within HTML. ```rust use hypertext::prelude::*; let shopping_list = ["milk", "eggs", "bread"]; let shopping_list_maud = maud! { div { h1 { "Shopping List" } ul { @for (i, item) in (1..).zip(shopping_list) { li.item { input #{ "item-" (i) } type="checkbox"; label for={ "item-" (i) } { (item) } } } } } } .render(); ``` -------------------------------- ### Rust Control Flow in `maud!` and `rsx!` Source: https://context7.com/vidhanio/hypertext/llms.txt Integrate standard Rust control flow structures like `@if`, `@for`, `@while let`, `@let`, and `@match` directly within `maud!` and `rsx!` macros for dynamic content generation. ```rust use hypertext::prelude::*; let values = [Some(1), None, Some(3)]; let status = "active"; let result = maud! { // @let binding @let title = "Results"; h2 { (title) } // @match with guards @match status { "active" => { span .green { "Active" } }, s if s.starts_with("err") => { span .red { (s) } }, _ => { span { "Unknown" } }, } // @for with @if ul { @for val in &values { @match val { Some(n) => { li { (n) } }, None => { li { "–" } }, } } } // @if let with @else @if let Some(n) = values[0] { p { "First: " (n) } } @else { p { "None" } } }.render(); assert_eq!( result.as_inner(), "

Results

Active
  • 1
  • 3

First: 1

" ); ``` -------------------------------- ### Defining Custom Elements with `define_elements!` Source: https://context7.com/vidhanio/hypertext/llms.txt Define custom HTML, void, SVG, or MathML elements. These macros generate the required `Element` and `GlobalAttributes` impls. ```Rust mod hypertext_elements { use hypertext::define_elements; pub use hypertext::validation::hypertext_elements::*; define_elements! { /// A custom web component greeting. greeting_card { /// The recipient's name. recipient /// Optional theme. theme } } } mod hypertext_elements2 { use hypertext::define_void_elements; pub use hypertext::validation::hypertext_elements::*; define_void_elements! { hr_fancy { width style } } } use hypertext::prelude::*; // Using the custom element { use hypertext_elements::*; let result = maud! { greeting-card recipient="Alice" theme="dark" { p { "Happy Birthday!" } } }.render(); assert_eq!( result.as_inner(), r###"

Happy Birthday!

"### ); } ``` -------------------------------- ### Check Without Default Features Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Checks the workspace without default features, crucial for testing the `no_std` path. ```bash cargo check --workspace --all-targets --no-default-features ``` -------------------------------- ### Generate HTML with maud! macro Source: https://context7.com/vidhanio/hypertext/llms.txt Use the maud! macro for Maud-inspired syntax to generate HTML. It supports dynamic values, conditional rendering, loops, and shorthand for IDs and classes. Void elements use a semicolon. ```rust use hypertext::prelude::*; let name = "Alice"; let logged_in = true; let items = ["milk", "eggs", "bread"]; let html = maud! { !DOCTYPE html lang="en" { head { title { "Shopping App" } } body { // id shorthand (#), class shorthand (.), and a regular attribute header #site-header .main-header role="banner" { h1 { "Hello, " (name) "!" } @if logged_in { a href="/logout" { "Log out" } } @else { a href="/login" { "Log in" } } } main { ul { @for (i, item) in (1..).zip(items) { li #{"item-" (i)} .item { input type="checkbox"; label for={"item-" (i)} { (item) } } } } } } } } .render(); // Output: Shopping App... assert!(html.as_inner().starts_with("")); ``` -------------------------------- ### SVG Markup with `svg::maud!` and `svg::rsx!` Source: https://context7.com/vidhanio/hypertext/llms.txt Dedicated macros for generating SVG. They validate against `hypertext_svg_elements` and emit self-closing tags for childless elements. ```Rust use hypertext::prelude::*; let radius: u32 = 40; let maud_svg = svg::maud! { svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" { circle cx="50" cy="50" r=(radius) fill="red"; g transform="translate(10,10)" { rect x="0" y="0" width="20" height="20" fill="blue"; } } }.render(); let rsx_svg = svg::rsx! { }.render(); assert_eq!(maud_svg.as_inner(), rsx_svg.as_inner()); assert_eq!( maud_svg.as_inner(), r###""### ); ``` -------------------------------- ### Generate HTML with rsx! macro Source: https://context7.com/vidhanio/hypertext/llms.txt Use the rsx! macro for JSX-like syntax to generate HTML. It supports dynamic expressions, conditional rendering, loops, and void elements. String literals must be quoted. ```rust use hypertext::prelude::*; let name = "Bob"; let score = 85; let html = rsx! {

"Welcome, " (name)

@if score >= 90 {

"Grade: A"

} @else if score >= 70 {

"Grade: B"

} @else {

"Grade: C"

}
    @for i in 1..=3 {
  • (i)
  • }
User avatar
} .render(); assert_eq!( html.as_inner(), r###"

Welcome, Bob

Grade: B

  • 1
  • 2
  • 3
User avatar
"### ); ``` -------------------------------- ### Define Renderable Components with `#[renderable]` Source: https://context7.com/vidhanio/hypertext/llms.txt Use the `#[renderable]` attribute to convert functions returning `impl Renderable` into reusable components. Parameters become struct fields, and the function name is converted to PascalCase for component usage. Supports conditional rendering with `@if`. ```rust use hypertext::prelude::*; #[renderable] fn nav_bar<'a>(title: &'a str, subtitle: &String, show_badge: bool) -> impl Renderable { maud! { nav { h1 { (title) } h2 { (subtitle) } @if show_badge { span .badge { "NEW" } } } } } // Used as a component via maud! component syntax let result = maud! { div { NavBar title="My Site" subtitle=("Welcome".to_owned()) show_badge=true; } }.render(); assert_eq!( result.as_inner(), r###"
"### ); // Custom struct name: #[renderable(MyBanner)] #[renderable(Banner)] fn _banner_impl<'a>(text: &'a str) -> impl Renderable { maud! { div .banner { (text) } } } let r = maud! { Banner text="Hello!"; }.render(); assert_eq!(r.as_inner(), r###""###); ``` -------------------------------- ### Buffer - Low-Level Rendering Buffer Source: https://context7.com/vidhanio/hypertext/llms.txt `Buffer` is a context-typed, XSS-safe wrapper around `String`. Used when implementing `Renderable` manually. Methods with `dangerously_` require an explicit `// XSS SAFETY:` justification comment. ```rust use hypertext::{Buffer, prelude::*}; fn trusted_html_fragment() -> String { "pre-sanitized".into() } let mut buffer = Buffer::new(); buffer.push(maud! { h1 { "My Document" } }); // XSS SAFETY: The fragment comes from a sanitizer that strips all scripts. buffer.dangerously_get_string().push_str(&trusted_html_fragment()); let result = buffer.rendered(); assert_eq!( result.as_inner(), "

My Document

pre-sanitized" ); ``` -------------------------------- ### Component Syntax with `children` Parameter Source: https://context7.com/vidhanio/hypertext/llms.txt Functions marked with `#[renderable]` can accept a `children` parameter of type `&R: Renderable`. This allows nested content to be passed and rendered within the component, supporting both `maud!` and `rsx!` syntax for defining children. ```rust use hypertext::prelude::*; #[renderable] fn panel(heading: &String, children: &R) -> impl Renderable { maud! { section .panel { h3 { (heading) } div .panel-body { (children) } } } } // maud! — children in braces let maud_result = maud! { Panel heading=("Settings".into()) { p { "Configure your preferences." } input type="text"; } }.render(); // rsx! — children between open/close tags let rsx_result = rsx! {

"Configure your preferences."

}.render(); assert_eq!( maud_result.as_inner(), r###"

Settings

Configure your preferences.

"### ); assert_eq!(maud_result.as_inner(), rsx_result.as_inner()); ``` -------------------------------- ### Inject Pre-Escaped HTML with `Raw` Source: https://context7.com/vidhanio/hypertext/llms.txt Use `Raw` to inject pre-escaped HTML strings, bypassing standard escaping. The `dangerously_create` constructor signals potential XSS risks, so use only with trusted or sanitized content. ```rust use hypertext::{Raw, prelude::*}; fn get_cms_html() -> String { // Assume CMS returns sanitized HTML "Bold from CMS".into() } let result = maud! { article { h1 { "My Post" } // XSS SAFETY: CMS output is sanitized before storage. (Raw::dangerously_create(get_cms_html())) } }.render(); assert_eq!( result.as_inner(), "

My Post

Bold from CMS
" ); ``` -------------------------------- ### Filter Tests by Substring Source: https://github.com/vidhanio/hypertext/blob/main/AGENTS.md Runs tests in a specific file that match a given substring in their names. ```bash cargo test -p hypertext --test integration blog_post --features default ``` -------------------------------- ### Optional Class Shorthands in `maud!` Source: https://context7.com/vidhanio/hypertext/llms.txt Conditionally include classes using `[condition]` or from an `Option` using `=[option_expr]` with the `.class` shorthand in `maud!`. ```rust use hypertext::prelude::*; let active = true; let extra: Option<&str> = Some("highlighted"); let result = maud! { div .base .active[active] .[extra] { "content" } }.render(); assert_eq!( result.as_inner(), r###"
content
"### ); ``` -------------------------------- ### Deriving `Renderable` with Inline Macros Source: https://context7.com/vidhanio/hypertext/llms.txt Use `#[derive(Renderable)]` with `#[maud(...)]`, `#[rsx(...)]`, or `#[attribute(...)]` to automatically implement the `Renderable` trait for structs. Supports both node and attribute rendering. ```rust use hypertext::prelude::*; // Node rendering via maud syntax #[derive(Renderable)] #[maud( div .card { h2 { (self.title) } p { (self.body) } } )] struct Card { title: String, body: String, } // Node rendering via rsx syntax #[derive(Renderable)] #[rsx("My name is " (self.name) "!")] struct NameTag { name: String } // Attribute value rendering #[derive(Renderable)] #[attribute((self.x) "," (self.y))] struct Coordinates { x: i32, y: i32 } let card = Card { title: "News".into(), body: "Content here.".into() }; assert_eq!( maud! { main { (card) } }.render().as_inner(), r###"

News

Content here.

"### ); assert_eq!( maud! { div title=(Coordinates { x: 10, y: 20 }) { "point" } }.render().as_inner(), r###"
point
"### ); ``` -------------------------------- ### Generate dynamic attribute values with attribute! macro Source: https://context7.com/vidhanio/hypertext/llms.txt Use the attribute! macro to generate dynamic attribute values, returning a LazyAttribute. This is useful for constructing attributes with control flow and can be used anywhere an attribute value expression is accepted. ```rust use hypertext::prelude::*; let active = true; let extra_classes = Some("highlighted"); // Build a class attribute value dynamically let class_attr = attribute! { "btn" @if active { " btn-active" } @if let Some(cls) = extra_classes { " " (cls) } }; let result = maud! { button class=class_attr { "Click me" } }.render(); assert_eq!( result.as_inner(), r###""### ); // Also works with @for let tab_ids = attribute! { "tab-" @for i in 0..3 { (i) } }; let result2 = maud! { div aria-owns=tab_ids {} }.render(); assert_eq!(result2.as_inner(), r###"
"###); ``` -------------------------------- ### Alias rsx! with html! macro Source: https://context7.com/vidhanio/hypertext/llms.txt The html! macro is an alias for rsx! to avoid name collisions with the Dioxus CLI rsx! macro. It has identical behavior and syntax. ```rust use hypertext::prelude::*; let result = html! {

"Same as rsx!"

} .render(); assert_eq!(result.as_inner(), r###"

Same as rsx!

"###); ``` -------------------------------- ### Implementing `Renderable` Trait for Custom Types Source: https://context7.com/vidhanio/hypertext/llms.txt Implement the `Renderable` trait to allow custom types to be embedded in `maud!` or `rsx!` macros using `(value)` interpolation. Implementations write to a `Buffer` for XSS safety. ```rust use hypertext::{Buffer, prelude::*}; pub struct Person { name: String, age: u8, } impl Renderable for Person { fn render_to(&self, buffer: &mut Buffer) { buffer.push(maud! { div .person { h2 { (self.name) } p { "Age: " (self.age) } } }); } } let person = Person { name: "Alice".into(), age: 30 }; let result = maud! { section { (person) } }.render(); assert_eq!( result.as_inner(), r###"

Alice

Age: 30

"### ); ``` -------------------------------- ### Built-in Framework Attribute Traits Source: https://context7.com/vidhanio/hypertext/llms.txt Enable optional Cargo features to unlock type-checked attributes for htmx, Alpine.js, and hyperscript. These are brought into scope automatically via `prelude::*`. ```toml # Cargo.toml [dependencies] hypertext = { version = "0.12", features = ["htmx", "alpine"] } ``` ```rust use hypertext::prelude::*; // HtmxAttributes and AlpineJsAttributes are in scope via prelude::* // htmx attributes (requires feature = "htmx") let htmx_result = maud! { div { button hx-get="/api/data" hx-target="#result" hx-swap="innerHTML" { "Load Data" } div #result {} } }.render(); assert_eq!( htmx_result.as_inner(), r###"
"### ); // Alpine.js attributes (requires feature = "alpine") let alpine_result = maud! { div x-data="{ open: false }" { button @click="open = !open" { "Toggle" } div x-show="open" { "Content" } } }.render(); assert_eq!( alpine_result.as_inner(), r###"
Content
"### ); ``` -------------------------------- ### Define Custom Attribute Traits Source: https://context7.com/vidhanio/hypertext/llms.txt Extend the type-checking system by defining a trait that extends GlobalAttributes. All elements automatically gain the attribute constants. ```rust use hypertext::{prelude::*, validation::Attribute}; // Define custom attributes for a fictional library trait MyLibraryAttrs: GlobalAttributes { const x_bind: Attribute = Attribute; const x_on: Attribute = Attribute; const x_show: Attribute = Attribute; } impl MyLibraryAttrs for T {} let result = maud! { div x-bind="isVisible" x-show="open" { button x-on="click" { "Toggle" } } }.render(); assert_eq!( result.as_inner(), r###"
"### ); ``` -------------------------------- ### maud::borrow! - Mutable Borrow Across Rendering Source: https://context7.com/vidhanio/hypertext/llms.txt A variant of `maud!` for situations where closures cannot take ownership, such as when iterating over a `RefCell`. It generates a borrowing closure. ```rust use core::cell::RefCell; use hypertext::prelude::*; let items = vec!["a", "b", "c"]; let iter = RefCell::new(items.into_iter()); let result = maud::borrow! { ul { @while let Some(item) = iter.borrow_mut().next() { li { (item) } } } } .render(); assert_eq!(result.as_inner(), "
  • a
  • b
  • c
"); ``` -------------------------------- ### Conditional Attributes with `[condition]` Suffix Source: https://context7.com/vidhanio/hypertext/llms.txt Use `[condition]` on attributes to omit them when the condition is false. `Option`-valued attributes use `=[option_expr]` syntax. Works with both `maud!` and `rsx!` macros. ```rust use hypertext::prelude::*; let is_checked = true; let is_disabled = false; let highlighted = true; let title: Option<&str> = Some("Tooltip text"); let label: Option<&str> = None; // maud! syntax let maud_result = maud! { input checked[is_checked] disabled[is_disabled] title=[title] aria-label=[label]; }.render(); assert_eq!( maud_result.as_inner(), r###""### ); // rsx! syntax — same behavior let rsx_result = rsx! {

"text"

}.render(); assert_eq!(rsx_result.as_inner(), r###"

text

"###); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.