EmailMessageHelper.js 638 B

12345678910111213141516171819202122232425262728
  1. const sanitizeHtml = require('sanitize-html')
  2. const sanitizeOptions = {
  3. html: {
  4. allowedTags: ['a', 'span', 'b', 'br', 'i'],
  5. allowedAttributes: {
  6. a: ['href', 'style'],
  7. span: ['style', 'class'],
  8. },
  9. },
  10. plainText: {
  11. allowedTags: [],
  12. allowedAttributes: {},
  13. },
  14. }
  15. function cleanHTML(text, isPlainText) {
  16. if (!isPlainText) return sanitizeHtml(text, sanitizeOptions.html)
  17. return sanitizeHtml(text, sanitizeOptions.plainText)
  18. }
  19. function displayLink(text, url, isPlainText) {
  20. return isPlainText ? `${text} (${url})` : `<a href="${url}">${text}</a>`
  21. }
  22. module.exports = {
  23. cleanHTML,
  24. displayLink,
  25. }