Commit 97b8693
String literal as macro content
Changed files (2)
Diff
@@ -141,6 +141,24 @@ let html = html! {{ }}; ``` +## Macro Content as String+If you find yourself fighting with the compiler about special characters like en dash or single quotes, +try using a raw string literal as macro content.++```rust+let test = String::from("bird");++let content = html! {{r#"+ <script>+ function test() {+ let result = 'TEST';+ let inter = "$test";+ return result;+ }+ </script>+"#}};+```+ ## Author and Contact - Written by Johan Mattsson - johan.mattsson.m@gmail.com@@ -251,5 +251,22 @@ fn test_script_compiles() { </script> }}; - assert!(content.contains("TEST"));+ assert!(content.contains("<script>"));+}++#[test]+fn test_script_string_compiles() {+ let test = String::from("bird");++ let content = html! {{r#"+ <script>+ function test() {+ let result = 'TEST';+ let inter = "$test";+ return result;+ }+ </script>+ "#}};++ assert!(content.contains("bird")); }