Clone in a terminal:
Commit 97b8693
Johan Mattsson - 2026-06-02T11:07:02+00:00
97b869349abc9d0d3f66f1eb29b5afd551a15bb9johan.mattsson.m@gmail.com

String literal as macro content

Changed files (2)

Diff

diff --git a/README.md b/README.mdindex 9067671..bd52a9e 100644--- a/README.md+++ b/README.md@@ -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.comdiff --git a/tests/other.rs b/tests/other.rsindex df61b97..0cc2f3f 100644--- a/tests/other.rs+++ b/tests/other.rs@@ -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")); }

Contact

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