WeHtml
Renders an HTML string after sanitizing it with DOMPurify (through useHtmlSanitizer). Use it instead of v-html for user-provided content, such as the output of we-tip-tap.
By default only the markup WeTipTap produces is kept:
- tags:
p,br,strong,b,em,i,u,s,code,pre,blockquote,h1–h6,ul,ol,li,hr,a - attributes:
href,target,rel,start,type
Everything else (scripts, event handlers, javascript: links, images, style, class, SVG, iframes, ...) is removed. Lists get their left padding back (Vuetify's reset removes it).
Usage
vue
<template>
<we-html :html="article.body" />
</template>Props
| Prop | Type | Default | Description |
|---|---|---|---|
html | string | undefined | HTML to sanitize and render |
options | { addTags?, addAttributes?, forbidTags?, forbidAttributes? } | undefined | Per-instance additions/exclusions, merged with the global we.html options (arrays are concatenated) |
vue
<template>
<!-- allow images, drop links -->
<we-html
:html="content"
:options="{ addTags: ['img'], addAttributes: ['src'], forbidTags: ['a'] }"
/>
</template>Global options
Project-wide additions/exclusions go in the module options:
ts
// nuxt.config.ts
export default defineNuxtConfig({
we: {
html: {
addTags: [],
addAttributes: [],
forbidTags: [],
forbidAttributes: [],
},
},
})Only additions and exclusions are possible: the base allow-list can't be replaced.
SSR
Sanitizing needs a DOM, so on the server the component renders an empty div. During hydration it is filled after mount; in SPA mode and on client-side navigation it is sanitized immediately.