Expand description
HTML rendering utilities.
This module provides structures and methods for creating and rendering HTML content with support for nested elements and text nodes.
§Examples
§Creating and rendering an HTML Tag
use cot::html::HtmlTag;
let tag = HtmlTag::new("br");
let html = tag.render();
assert_eq!(html.as_str(), "<br/>");§Adding Attributes to an HTML Tag
use cot::html::HtmlTag;
let mut tag = HtmlTag::new("input");
tag.attr("type", "text").attr("placeholder", "Enter text");
tag.bool_attr("disabled");
assert_eq!(
tag.render().as_str(),
"<input type=\"text\" placeholder=\"Enter text\" disabled/>"
);§Creating nested HTML elements
use cot::html::{Html, HtmlTag};
let mut div = HtmlTag::new("div");
div.attr("class", "container");
div.push_str("Hello, ");
let mut span = HtmlTag::new("span");
span.attr("class", "highlight");
span.push_str("world!");
div.push_tag(span);
let html = div.render();
assert_eq!(
html.as_str(),
"<div class=\"container\">Hello, <span class=\"highlight\">world!</span></div>"
);