Skip to content

Commit c84b097

Browse files
docs: update canary rendering raw HTML page
1 parent 35b696d commit c84b097

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description: |
3+
How to render raw HTML in Fresh.
4+
---
5+
6+
Text content in Fresh is always escaped, whether serverside rendered or rendered
7+
in islands. While this generally desired, it can create issues in certain
8+
situations.
9+
10+
To address this you can render raw HTML via Preact's `dangerouslySetInnerHTML`
11+
prop:
12+
13+
```tsx
14+
<div dangerouslySetInnerHTML={{ __html: "<h1>This is raw HTML</h1>" }} />;
15+
```
16+
17+
This will output:
18+
19+
```html
20+
<div>
21+
<h1>This is raw HTML</h1>
22+
</div>
23+
```
24+
25+
A common use case for rendering raw HTML is syntax highlighting code blocks or
26+
rendering markdown.
27+
28+
> [warn]: Setting arbitrary HTML can be dangerous, hence the
29+
> `dangerouslySetInnerHTML` naming. Make sure you trust the source. Rendering
30+
> user-supplied HTML to the DOM makes your site vulnerable to cross- site
31+
> scripting. The markup must first be sanitizied, or better yet, something you
32+
> trust.

docs/toc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const toc: RawTableOfContents = {
8282
["modifying-the-head", "Modifying the <head>", "link:latest"],
8383
["creating-a-crud-api", "Creating a CRUD API", "link:latest"],
8484
["rendering-markdown", "Rendering markdown", "link:latest"],
85-
["rendering-raw-html", "Rendering raw HTML", "link:latest"],
85+
["rendering-raw-html", "Rendering raw HTML", "link:canary"],
8686
[
8787
"sharing-state-between-islands",
8888
"Sharing state between islands",

0 commit comments

Comments
 (0)