https://github.com/ecosia/vue-safe-html
A Vue directive which renders sanitised HTML dynamically
https://github.com/ecosia/vue-safe-html
Last synced: 2 months ago
JSON representation
A Vue directive which renders sanitised HTML dynamically
- Host: GitHub
- URL: https://github.com/ecosia/vue-safe-html
- Owner: ecosia
- License: other
- Created: 2021-01-12T11:01:56.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-12-03T17:59:41.000Z (4 months ago)
- Last Synced: 2025-12-06T22:53:11.736Z (4 months ago)
- Language: JavaScript
- Size: 438 KB
- Stars: 32
- Watchers: 10
- Forks: 5
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-vue - vue-safe-html - Vue.js directive which renders sanitised HTML dynamically. (Components & Libraries / Utilities)
- awesome-vue - vue-safe-html - A Vue directive which renders sanitised HTML dynamically ` 📝 2 months ago` (Utilities [🔝](#readme))
- fucking-awesome-vue - vue-safe-html - Vue.js directive which renders sanitised HTML dynamically. (Components & Libraries / Utilities)
- awesome-vue - vue-safe-html - Vue.js directive which renders sanitised HTML dynamically. (Components & Libraries / Utilities)
README
# vue-safe-html

[](https://www.npmjs.com/package/vue-safe-html)
[](https://github.com/ecosia/vue-safe-html/tree/main)
[](https://vuejs.org)
[](https://v3.vuejs.org)
A Vue directive which renders sanitised HTML dynamically. Zero dependencies, compatible with Vue versions 3 and 2, TypeScript-ready.
**Note:** This library is not XSS-safe, but only strips tags programmatically.
## Installation
Install package:
```sh
npm install vue-safe-html
# OR
yarn add vue-safe-html
```
Use the plugin:
```js
import Vue from 'vue';
import VueSafeHTML from 'vue-safe-html';
Vue.use(VueSafeHTML);
```
## Usage
In your component:
```html
```
```js
export default {
computed: {
myUnsafeHTML() {
return 'oh my! I am safe!';
}
}
}
```
Renders to:
```html
I am safe!
```
### Options
#### allowedTags
Array of strings. Default: `['a', 'b', 'br', 'strong', 'i', 'em', 'mark', 'small', 'del', 'ins', 'sub', 'sup']`.
Customize the tags that are allowed to be rendered, either by providing new ones:
```js
Vue.use(VueSafeHTML, {
allowedTags: ['marquee', 'blockquote'],
});
```
Or extending the default ones:
```js
import VueSafeHTML, { allowedTags } from 'vue-safe-html';
Vue.use(VueSafeHTML, {
allowedTags: [...allowedTags, 'marquee', 'blockquote'],
});
```
If no tags are passed, all tags are stripped:
```js
import VueSafeHTML from 'vue-safe-html';
Vue.use(VueSafeHTML, {
allowedTags: [],
});
```
It is also possible to provide custom allowed tags directly to the directive tag, using directive modifiers. This allows local override of the option:
```html
```
#### allowedAttributes
Array of strings. Default: []
Customize the tag attributes that are allowed to be rendered:
```js
Vue.use(VueSafeHTML, {
allowedTags: ['a'],
allowedAttributes: ['title', 'class', 'href'],
});
```
### Nuxt
`vue-safe-html` is written as a Vue plugin so you can easily use it inside Nuxt by following [the Nuxt documentation](https://nuxtjs.org/docs/2.x/directory-structure/plugins#vue-plugins).
## License
[Do No Harm](./LICENSE)