nuxt-sanitize-html
Sanitize HTML for Nuxt
For usage of sanitize-html, see the official repo Usage:
// nuxt.config
{
buildModules: [
'nuxt-sanitize-html',
],
sanitizeHtml: {
allowedAttributes: {
h3: ['style']
}
}
}
<template>
<div>
<!-- sanitize in template-->
<div v-html="$sanitize(dirty)"></div>
<!-- or before-->
<div v-html="clean"></div>
</div>
</template>
<script setup lang="ts">
import {useNuxtApp} from "nuxt3/app";
// <!-- sanitize in template-->
const dirty = '<h3 style="color:red" onmouseenter="alert(`Something else`)">I do not alert something!</h3>'
// <!-- or before-->
const nuxtApp = useNuxtApp()
const clean = nuxtApp.$sanitize(dirty)
</script>
Development
- Run
npm run dev:prepareto generate type stubs. - Use
npm run devto start playground in development mode.
I'm as new as anyone to Nuxt modules, so PR's to make this module better are appreciated!
Related Packages
purrrify
A Nuxt module that integrates sanitize-html for sanitizing HTML content and prot...
2,066
4
@nathanchase/nuxt-dayjs-module
This is a Nuxt 3 compatible module built with the official Nuxt 3 (module-builde...
19,376
31
Version History
| Version | Released | License |
|---|---|---|
| 0.1.8 | MIT |