Allows you to use JSX and HTML with proper headers and support.
Install with:
Then use it:
This plugin will automatically add Content-Type: text/html; charset=utf8
header to the response, add <!doctype html>
and convert it into a Response object.
Elysia HTML is based on @kitajs/html allowing us to define JSX to string in compile time to archive high performance.
Name your file that need to use JSX to ends with affix "x":
To register TypeScript type, please appends the following to tsconfig.json:
That's it, now you can JSX as your template engine:
Elysia HTML is based use with Kita HTML plugin to detect possible XSS attack in compile time.
You can use a dedicated safe
attribute to sanitize user value to prevent XSS vulnerability.
However, when are building a large-scale app, it's best to have a type reminder to detect possible XSS vulnerability in your codebase.
To add a type-safe reminder, please install:
Then appends the following **tsconfig.json
string
'text/html; charset=utf8'
The content-type of the response.
boolean
true
Whether to automatically detect HTML content and set the content-type.
boolean | 'full'
true
Whether to automatically add <!doctype html>
to a response starting with <html>
, if not found.
Use full
to also automatically add doctypes on responses returned without this plugin
(value: string) => boolean
isHtml
(exported function)The function used to detect if a string is a html or not. Default implementation if length is greater than 7, starts with <
and ends with >
.
Keep in mind there's no real way to validate HTML, so the default implementation is a best guess.