File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,38 @@ user=> (str (h/html [:p (h/raw "Hello <em>World</em>")]))
77
77
" <p>Hello <em>World</em></p>"
78
78
```
79
79
80
+ This can also be used for doctype declarations:
81
+
82
+ ``` clojure
83
+ user=> (str (h/html (h/raw " <!DOCTYPE html>" ) [:html {:lang " en" }]))
84
+ " <!DOCTYPE html><html lang=\" en\" ></html>"
85
+ ```
86
+
87
+ ## Differences between Hiccup 1 and 2
88
+
89
+ In brief: Hiccup 1 doesn't escape strings by default, while Hiccup 2
90
+ does. They occupy different namespaces to ensure backward compatibility.
91
+
92
+ In Hiccup 1, you use the ` h ` function to escape a string - that is,
93
+ ensure that unsafe characters like ` < ` , ` > ` and ` & ` are converted into
94
+ their equivalent entity codes:
95
+
96
+ ``` clojure
97
+ (h1/html [:div " Username: " (h1/h username)])
98
+ ```
99
+
100
+ In Hiccup 2 strings are escaped automatically, but the return value from
101
+ the ` html ` macro is a ` RawString ` , rather than a ` String ` . This ensures
102
+ that the ` html ` macro can still be nested.
103
+
104
+ ``` clojure
105
+ (str (h2/html [:div " Username: " username]))
106
+ ```
107
+
108
+ It's recommended to use Hiccup 2 where possible, particularly if your
109
+ app handles user data. Use of the non-core namespaces, such as
110
+ ` hiccup.page ` , should be avoided with Hiccup 2.
111
+
80
112
## License
81
113
82
114
Copyright © 2023 James Reeves
You can’t perform that action at this time.
0 commit comments