Clone in a terminal:
injection.rs
tests/ - Escape less
// Copyright (c) 2026 Johan Mattsson // License: MIT use kaja_html_macro::html; fn another_injection() -> String { return "<script>anothertest</script>".to_string(); } fn include_tag_function() -> String { return "<includedtag>OK</includedtag>".to_string(); } #[test] fn test_include() { let html = html! {{ <html> <body> <include include_tag_function() /> </body> </html> }}; println!("Generated HTML: {:?}", html); assert!(html.contains("<includedtag>OK</includedtag>")); } #[test] fn test_escape_tag() { let injection = "<script>test</script>"; let html = html! {{ <html> <body> $injection $(another_injection()) <include include_tag_function() /> </body> </html> }}; println!("Generated HTML: {:?}", html); assert!(html.contains("<html>")); assert!(html.contains("</html>")); assert!(!html.contains("<script>test</script>")); assert!(html.contains("&lt;script&gt;test&lt;/script&gt;")); assert!(html.contains("&lt;script&gt;anothertest&lt;/script&gt;")); assert!(html.contains("<includedtag>OK</includedtag>")); }

File history (4 commits)

09d6d11 Johan Mattsson - johan.mattsson.m@gmail.com
Escape less
Escape less
5666609 Johan Mattsson - johan.mattsson.m@gmail.com
Rename project to kaja-html-macro
Rename project to kaja-html-macro
02c8b48 Johan Mattsson - johan.mattsson.m@gmail.com
Add copyright header
Add copyright header

MIT license
c95af61 Johan Mattsson - johan.mattsson.m@gmail.com
HTML macro for Rust projects
HTML macro for Rust projects

This is a macro that creates a Rust String from an HTML block.

Example:
let content = html!{{ <html></html> }}

Created by Johan Mattsson for Kajacode.

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112