2020-07-27 10:34:07 -04:00
|
|
|
const sanitizeHtml = require('sanitize-html')
|
|
|
|
const sanitizeOptions = {
|
|
|
|
html: {
|
|
|
|
allowedTags: ['span', 'b', 'br', 'i'],
|
|
|
|
allowedAttributes: {
|
2021-04-27 03:52:58 -04:00
|
|
|
span: ['style', 'class'],
|
|
|
|
},
|
2020-07-27 10:34:07 -04:00
|
|
|
},
|
|
|
|
plainText: {
|
|
|
|
allowedTags: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
allowedAttributes: {},
|
|
|
|
},
|
2020-07-27 10:34:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2021-04-27 03:52:58 -04:00
|
|
|
displayLink,
|
2020-07-16 11:41:19 -04:00
|
|
|
}
|