@@ -26,7 +26,7 @@ rendering the payload as harmless text.
2626Place ` safe ` on the innermost element that holds the untrusted value. Do not add it to a
2727parent wrapper, as that would escape the HTML of child components too.
2828
29- ``` tsx
29+ ``` tsx twoslash kita
3030function UserCard({ name , bio }: { name: string ; bio: string }) {
3131 return (
3232 <div class = " card" >
@@ -35,6 +35,8 @@ function UserCard({ name, bio }: { name: string; bio: string }) {
3535 </div >
3636 )
3737}
38+ // ---cut-after---
39+ const html = <UserCard name = " Name" bio = " Bio" />
3840```
3941
4042## Component children
@@ -64,13 +66,16 @@ html = <MyComponent>{escapeHtml(userInput)}</MyComponent>
6466
6567## Template literal helper
6668
67- The ` e ` tagged template escapes interpolated values while preserving literal HTML around
68- them.
69+ The ` e ` tagged template is an alias to ` escapeHtml() ` that you can use as interpolated
70+ content in template literals. It provides a convenient way to escape dynamic values
71+ outside of JSX.
6972
70- ``` tsx
73+ ``` tsx twoslash kita
74+ const userName = ' <script>untrusted()</script>' as const
75+ // ---cut---
7176import { e } from ' @kitajs/html'
7277
73- const html = e ` <p> Hello, ${userName }!</p> `
78+ const html = e ` Hello, ${userName }! `
7479```
7580
7681## Suppression conventions
@@ -111,15 +116,29 @@ const unsafeContent = 'My safe string' as const
111116const html = <div >{ unsafeContent } </div >
112117```
113118
119+ ::: warning
120+
121+ Manual casts and naming conventions are not enforced by the compiler. They rely on
122+ developer discipline and code reviews to ensure safety. Use them judiciously and document
123+ the rationale for any exceptions.
124+
125+ :::
126+
114127Cast the expression to ` 'safe' ` inline. This tells the plugin to skip the check for that
115- specific usage.
128+ specific usage and not warn about possible XSS vulnerabilities .
116129
117- ``` tsx
118- <div >{ content as ' safe' } </div >
130+ ``` tsx twoslash kita
131+ const content: string = ' <script>untrusted()</script>'
132+ // ---cut---
133+ const html = <div >{ content as ' safe' } </div >
119134```
120135
121136Call ` Html.escapeHtml() ` directly. The plugin recognizes the return value as escaped.
122137
123- ``` tsx
124- <div >{ Html .escapeHtml (content )} </div >
138+ ``` tsx twoslash kita
139+ const content: string = ' <script>untrusted()</script>'
140+ // ---cut---
141+ import { Html } from ' @kitajs/html'
142+
143+ const html = <div >{ Html .escapeHtml (content )} </div >
125144```
0 commit comments