//! Create HTML by manipulating elements as structured data. Inspired by the //! clojure library [hiccup][hiccup]. //! //! [hiccup]: https://github.com/weavejester/hiccup #[cfg(feature = "axum")] mod axum; mod check; mod element; pub mod html; pub mod mathml; mod render; pub mod svg; pub use self::{element::*, render::*}; #[cfg(test)] mod tests { use crate::{html::*, Attr, Content, Element, Render}; #[test] fn simple_website() { let els = [ Content::doctype(), html(( head(title("Hello")), body((h1("Hello"), p(("Hello ", em("world"), "!")))), )) .into(), ]; assert_eq!( els.render_to_string().unwrap(), concat!( "", "Hello", "

Hello

Hello world!

", "", ), ); } #[test] fn void_elements() { // Difference between void and non-void assert_eq!(head(()).render_to_string().unwrap(), ""); assert_eq!(input(()).render_to_string().unwrap(), ""); // Void elements must not contain any children assert!(input(p(())).render_to_string().is_err()); } #[test] fn raw_text_elements() { assert_eq!( script("foo ", ); println!("{:?}", script("hello world").render_to_string(),); assert!(script("hello world").render_to_string().is_err()); assert!(script("hello & bar").render_to_string().unwrap(), "", ); assert!(textarea(p(())).render_to_string().is_err()); } #[test] fn attributes() { assert_eq!( input(( Attr::new("name", "tentacles"), Attr::new("type", "number"), Attr::new("min", 10), Attr::new("max", 100), )) .render_to_string() .unwrap(), r#""#, ); assert_eq!( input((Attr::new("name", "horns"), Attr::yes("checked"))) .render_to_string() .unwrap(), r#""#, ); } #[test] fn always_lowercase() { assert_eq!( Element::normal("HTML") .with(Attr::new("LANG", "EN")) .render_to_string() .unwrap(), r#""#, ); } }