Created
March 27, 2015 10:40
-
-
Save dstollie/ef8131cbfac2600441a0 to your computer and use it in GitHub Desktop.
Simple purify method for meteor which uses cristo-rabani's package: https://github.com/cristo-rabani/meteor-universe-html-purifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
purify = function(text, allowedTags, allowedAttributes) { | |
if(!allowedTags) allowedTags = ['b', 'i', 'strong', 'em', 'ol', 'ul', 'li', 'p', 'span', 'a', 'img', 'br']; | |
if(!allowedAttributes) allowedAttributes = ['href', 'src']; | |
var disallowedTags = ['b', 'i', 'strong', 'em', 'blockquote', 'ol', 'ul', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'p', 'span', 'pre', 'a', 'u', 'img', 'br', 'table']; | |
// Check the difference between the default enabled tags and the allowed tags | |
var disallowedTags = _.difference(disallowedTags, allowedTags); | |
// Don't allow extra attributes to an element | |
UniHTML.setNewAllowedAttributes(allowedAttributes, 'all_elements'); | |
// Purify the answer text and stripe disallowed tags | |
var purified = UniHTML.purify(text, { | |
withoutTags: disallowedTags | |
}); | |
return purified; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment