Last active
January 27, 2022 03:47
-
-
Save alltom/c358fdaf07b202eedf95d6c9c5446338 to your computer and use it in GitHub Desktop.
"Tested" with Trix 0.9.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sanitizeHtml = require('sanitize-html'); | |
function localSanitizeHtml(html) { | |
let allowedAttributes = JSON.parse(JSON.stringify(sanitizeHtml.defaults.allowedAttributes)); | |
allowedAttributes.a = (allowedAttributes.a || []).concat(['data-trix-attachment', 'rel']); | |
allowedAttributes.figure = (allowedAttributes.figure || []).concat(['class']); | |
allowedAttributes.figcaption = (allowedAttributes.figcaption || []).concat(['class']); | |
allowedAttributes.img = (allowedAttributes.img || []).concat(['width', 'height']); | |
allowedAttributes.span = (allowedAttributes.span || []).concat(['class']); | |
return sanitizeHtml(html, { | |
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'figure', 'figcaption', 'span', 'del']), | |
allowedAttributes: allowedAttributes, | |
transformTags: { | |
a: function(tagName, attribs) { | |
attribs.target = '_blank'; | |
attribs.rel = 'noreferrer'; | |
return { tagName: tagName, attribs: attribs }; | |
}, | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment