Last active
August 29, 2015 14:18
-
-
Save dstollie/e818368e13b27078aca5 to your computer and use it in GitHub Desktop.
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
if(Meteor.isServer) { | |
cheerio = Npm.require("cheerio"); | |
} | |
validEmail = function (email) { | |
var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
return re.test(email); | |
}; | |
purify = function(text, allowedTags, allowedAttributes) { | |
console.log(text); | |
if(Meteor.isServer) { | |
text = replaceTextSections(text); | |
} | |
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; | |
}; | |
var replaceTextSections = function(text) { | |
if(Meteor.isServer) { | |
$ = cheerio.load(text); | |
} | |
$('br').after('<br>'); | |
console.log($); | |
return $.html(); | |
}; |
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
Package.describe({ | |
name: 'myapp-common', | |
version: '0.0.1', | |
// Brief, one-line summary of the package. | |
summary: '', | |
// URL to the Git repository containing the source code for this package. | |
git: '', | |
// By default, Meteor will default to using README.md for documentation. | |
// To avoid submitting documentation, set this field to null. | |
documentation: 'README.md' | |
}); | |
Npm.depends({cheerio: '0.19.0'}); | |
Package.onUse(function(api) { | |
api.use([ | |
'tap:i18n', | |
'myapp-i18n', | |
'vazco:universe-html-purifier', | |
'wtfzn:dompurify' | |
]); | |
api.use(['jquery', 'session'], 'client'); | |
api.addFiles([ | |
'myapp-common.js' | |
]); | |
api.export([ | |
'purify', | |
'trans', | |
'validEmail', | |
'cheerio' | |
]); | |
}); | |
Package.onTest(function(api) { | |
api.use('tinytest'); | |
api.use('myapp-common'); | |
api.addFiles('myapp-common-tests.js'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment