Skip to content

The open alternative to Salesforce, designed for AI.

1.1 KB
Raw Blame
import sanitizeHtml from 'sanitize-html';

const TEXT_SHAPING_TAGS = [
  'a',
  'article',
  'aside',
  'b',
  'blockquote',
  'br',
  'caption',
  'center',
  'dd',
  'div',
  'dl',
  'dt',
  'em',
  'figcaption',
  'figure',
  'font',
  'footer',
  'h1',
  'h2',
  'h3',
  'h4',
  'h5',
  'h6',
  'header',
  'hr',
  'i',
  'img',
  'li',
  'main',
  'nav',
  'ol',
  'p',
  'pre',
  's',
  'section',
  'span',
  'strong',
  'sub',
  'sup',
  'table',
  'tbody',
  'td',
  'tfoot',
  'th',
  'thead',
  'tr',
  'u',
  'ul',
];

const TAGS_CARRYING_NO_BODY_TEXT = [
  'applet',
  'embed',
  'head',
  'iframe',
  'noscript',
  'object',
  'option',
  'script',
  'style',
  'template',
  'textarea',
  'title',
];

export const MESSAGE_HTML_SANITIZE_OPTIONS = {
  allowedTags: TEXT_SHAPING_TAGS,
  allowedAttributes: {
    a: ['href'],
    img: ['src', 'alt'],
    '*': ['title', 'class', 'id', 'style'],
  },
  allowedSchemes: ['http', 'https', 'mailto', 'tel'],
  disallowedTagsMode: 'discard',
  nonTextTags: TAGS_CARRYING_NO_BODY_TEXT,
  nestingLimit: 256,
} satisfies sanitizeHtml.IOptions;