在我们的应用程序中,对于一个非常特定的场景(只在一个地方),我们需要绕过标记,并使用DOMPurify将其呈现在DOM上。
var htmlScript = "<style>*{color: red}</style>"; // something like this
var clean = dompurify.sanitize(htmlScript, { ADD_TAGS: ['style']});
return clean;
有谁知道如何实现它吗?
发布于 2020-09-07 10:50:30
我相信您可以使用these 3 options:FORCE_BODY
、ALLOWED_TAGS
和ALLOWED_ATTR
来做到这一点。
示例:
outHtml = domPurify.sanitize(outHtml, {
FORCE_BODY: true,
ALLOWED_ATTR: ['style', 'class', 'type', 'href', 'rel'],
// must add these tag manually if use this option.
ALLOWED_TAGS: [
'link',
'figure',
'table',
'caption',
'thead',
'tr',
'th',
'tbody',
'td',
],
});
https://stackoverflow.com/questions/62394381
复制相似问题