nuxt-sanitize-html
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

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:prepare to generate type stubs.
  • Use npm run dev to start playground in development mode.

I'm as new as anyone to Nuxt modules, so PR's to make this module better are appreciated!

Package Sidebar

Install

npm i nuxt-sanitize-html

Weekly Downloads

8

Version

0.1.8

License

MIT

Unpacked Size

7.07 kB

Total Files

14

Last publish

Collaborators

  • newtee