1 export function getDefaultSanitizeOptions () {
3 allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ],
4 allowedSchemes: [ 'http', 'https' ],
6 'a': [ 'href', 'class', 'target', 'rel' ],
10 a: (tagName: string, attribs: any) => {
11 let rel = 'noopener noreferrer'
12 if (attribs.rel === 'me') rel += ' me'
16 attribs: Object.assign(attribs, {
26 export function getTextOnlySanitizeOptions () {
28 allowedTags: [] as string[]
32 export function getCustomMarkupSanitizeOptions (additionalAllowedTags: string[] = []) {
33 const base = getDefaultSanitizeOptions()
38 ...additionalAllowedTags,
39 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img'
42 ...base.allowedSchemes,
47 ...base.allowedAttributes,
49 'img': [ 'src', 'alt' ],
50 '*': [ 'data-*', 'style' ]
55 // Thanks: https://stackoverflow.com/a/12034334
56 export function escapeHTML (stringParam: string) {
57 if (!stringParam) return ''
59 const entityMap: { [id: string ]: string } = {
70 return String(stringParam).replace(/[&<>"'`=/]/g, s => entityMap[s])