diff --git a/docs/canary/examples/rendering-raw-html.md b/docs/canary/examples/rendering-raw-html.md new file mode 100644 index 00000000..bc1db90b --- /dev/null +++ b/docs/canary/examples/rendering-raw-html.md @@ -0,0 +1,32 @@ +--- +description: | + How to render raw HTML in Fresh. +--- + +Text content in Fresh is always escaped, whether serverside rendered or rendered +in islands. While this generally desired, it can create issues in certain +situations. + +To address this you can render raw HTML via Preact's `dangerouslySetInnerHTML` +prop: + +```tsx +
This is raw HTML" }} />; +``` + +This will output: + +```html +
+

This is raw HTML

+
+``` + +A common use case for rendering raw HTML is syntax highlighting code blocks or +rendering markdown. + +> [warn]: Setting arbitrary HTML can be dangerous, hence the +> `dangerouslySetInnerHTML` naming. Make sure you trust the source. Rendering +> user-supplied HTML to the DOM makes your site vulnerable to cross- site +> scripting. The markup must first be sanitizied, or better yet, something you +> trust. diff --git a/docs/toc.ts b/docs/toc.ts index 51715540..c6aa621f 100644 --- a/docs/toc.ts +++ b/docs/toc.ts @@ -82,7 +82,7 @@ const toc: RawTableOfContents = { ["modifying-the-head", "Modifying the ", "link:latest"], ["creating-a-crud-api", "Creating a CRUD API", "link:latest"], ["rendering-markdown", "Rendering markdown", "link:latest"], - ["rendering-raw-html", "Rendering raw HTML", "link:latest"], + ["rendering-raw-html", "Rendering raw HTML", "link:canary"], [ "sharing-state-between-islands", "Sharing state between islands",