0.1.8 • Published 2 years ago

nuxt-sanitize-html v0.1.8

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
2 years ago

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!