renderer.js 597 B

123456789101112131415161718192021222324
  1. const { JSDOM } = require('jsdom')
  2. const createDOMPurify = require('dompurify')
  3. module.exports = {
  4. async init(input, config) {
  5. if (config.safeHTML) {
  6. const window = new JSDOM('').window
  7. const DOMPurify = createDOMPurify(window)
  8. const allowedAttrs = ['v-pre', 'v-slot:tabs', 'v-slot:content', 'target']
  9. const allowedTags = ['tabset', 'template']
  10. if (config.allowIFrames) {
  11. allowedTags.push('iframe')
  12. }
  13. input = DOMPurify.sanitize(input, {
  14. ADD_ATTR: allowedAttrs,
  15. ADD_TAGS: allowedTags
  16. })
  17. }
  18. return input
  19. }
  20. }