Copy Knossos parser changes to Omorphia (#76)

This commit is contained in:
Brady 2023-06-28 13:13:25 -02:30 committed by GitHub
parent 33f3479569
commit dd205e849c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,14 +14,17 @@ export const configuredXss = new xss.FilterXSS({
kbd: ['id'], kbd: ['id'],
input: ['checked', 'disabled', 'type'], input: ['checked', 'disabled', 'type'],
iframe: ['width', 'height', 'allowfullscreen', 'frameborder', 'start', 'end'], iframe: ['width', 'height', 'allowfullscreen', 'frameborder', 'start', 'end'],
img: [...xss.whiteList.img, 'usemap'], img: [...xss.whiteList.img, 'usemap', 'style'],
map: ['name'], map: ['name'],
area: [...xss.whiteList.a, 'coords'], area: [...xss.whiteList.a, 'coords'],
a: [...xss.whiteList.a, 'rel'], a: [...xss.whiteList.a, 'rel'],
td: [...xss.whiteList.td, 'style'],
th: [...xss.whiteList.th, 'style'],
}, },
css: { css: {
whiteList: { whiteList: {
'image-rendering': /^pixelated$/, 'image-rendering': /^pixelated$/,
'text-align': /^center|left|right$/,
}, },
}, },
onIgnoreTagAttr: (tag, name, value) => { onIgnoreTagAttr: (tag, name, value) => {
@ -50,12 +53,14 @@ export const configuredXss = new xss.FilterXSS({
} }
// For Highlight.JS // For Highlight.JS
if ( if (name === 'class' && ['pre', 'code', 'span'].includes(tag)) {
name === 'class' && const allowedClasses = []
['pre', 'code', 'span'].includes(tag) && for (const className of value.split(/\s/g)) {
(value.startsWith('hljs-') || value.startsWith('language-')) if (className.startsWith('hljs-') || className.startsWith('language-')) {
) { allowedClasses.push(className)
return name + '="' + xss.escapeAttrValue(value) + '"' }
}
return name + '="' + xss.escapeAttrValue(allowedClasses.join(' ')) + '"'
} }
}, },
safeAttrValue(tag, name, value, cssFilter) { safeAttrValue(tag, name, value, cssFilter) {