2020-07-27 10:34:07 -04:00
|
|
|
const sanitizeHtml = require('sanitize-html')
|
|
|
|
const sanitizeOptions = {
|
|
|
|
html: {
|
|
|
|
allowedTags: ['span', 'b', 'br', 'i'],
|
|
|
|
allowedAttributes: {
|
|
|
|
span: ['style', 'class']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plainText: {
|
|
|
|
allowedTags: [],
|
|
|
|
allowedAttributes: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanHTML(text, isPlainText) {
|
|
|
|
if (!isPlainText) return sanitizeHtml(text, sanitizeOptions.html)
|
|
|
|
return sanitizeHtml(text, sanitizeOptions.plainText)
|
|
|
|
}
|
|
|
|
|
2020-07-16 11:41:19 -04:00
|
|
|
function displayLink(text, url, isPlainText) {
|
|
|
|
return isPlainText ? `${text} (${url})` : `<a href="${url}">${text}</a>`
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2020-07-27 10:34:07 -04:00
|
|
|
cleanHTML,
|
2020-07-16 11:41:19 -04:00
|
|
|
displayLink
|
|
|
|
}
|