Skip to content

Adds schema type "Html" to mongoose for handling sanitized html

Notifications You must be signed in to change notification settings

NRGI/mongoose-html

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What it does

How to use

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// Will add the Currency type to the Mongoose Schema types
require('mongoose-html').loadType(mongoose);
var Html = mongoose.Types.Html;

// If you don't have the Html variable declared you can use 'mongoose.Types.Html'
var ContentSchema = Schema({
  richContent: {
    type: Html,
    setting: {
      allowedTags: ['p', 'b', 'i', 'em', 'strong', 'a'],
      allowedAttributes: {
        'a': ['href']
      }
    }
  }
});

var Content = mongoose.model('Content', ContentSchema);

var content = new Content({ richContent: "<a href='http://google.com' style='display:block'>google</a>" });

How to install

  • npm i mongoose-html

How to test

  • sudo npm i mocha -g
  • mocha test

Schema options

Same as sanitize-html https://github.com/punkave/sanitize-html

About author

Created by Homer Quan for reflen.com

About

Adds schema type "Html" to mongoose for handling sanitized html

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%