// 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("<script>test</script>"));
assert!(html.contains("<script>anothertest</script>"));
assert!(html.contains("<includedtag>OK</includedtag>"));
}
File history (4 commits)
Escape less
Escape less
Rename project to kaja-html-macro
Rename project to kaja-html-macro
Add copyright header
Add copyright header
MIT license
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.