mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
5 years ago
|
const { JSDOM } = require('jsdom')
|
||
|
const createDOMPurify = require('dompurify')
|
||
6 years ago
|
|
||
5 years ago
|
module.exports = {
|
||
|
async init(input, config) {
|
||
|
if (config.safeHTML) {
|
||
5 years ago
|
const window = new JSDOM('').window
|
||
|
const DOMPurify = createDOMPurify(window)
|
||
|
|
||
5 years ago
|
const allowedAttrs = ['v-pre', 'v-slot:tabs', 'v-slot:content', 'target']
|
||
5 years ago
|
const allowedTags = ['tabset', 'template']
|
||
|
|
||
4 years ago
|
if (config.allowDrawIoUnsafe) {
|
||
|
allowedTags.push('foreignObject')
|
||
|
DOMPurify.addHook('uponSanitizeElement', (elm) => {
|
||
|
if (elm.querySelectorAll) {
|
||
|
const breaks = elm.querySelectorAll('foreignObject br, foreignObject p')
|
||
|
if (breaks && breaks.length) {
|
||
|
for (let i = 0; i < breaks.length; i++) {
|
||
|
breaks[i].parentNode.replaceChild(
|
||
|
window.document.createElement('div'),
|
||
|
breaks[i]
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
5 years ago
|
if (config.allowIFrames) {
|
||
|
allowedTags.push('iframe')
|
||
4 years ago
|
allowedAttrs.push('allow')
|
||
5 years ago
|
}
|
||
|
|
||
|
input = DOMPurify.sanitize(input, {
|
||
|
ADD_ATTR: allowedAttrs,
|
||
|
ADD_TAGS: allowedTags
|
||
5 years ago
|
})
|
||
|
}
|
||
|
return input
|
||
6 years ago
|
}
|
||
|
}
|