Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Copy Knossos parser changes to Omorphia #76

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/helpers/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ export const configuredXss = new xss.FilterXSS({
kbd: ['id'],
input: ['checked', 'disabled', 'type'],
iframe: ['width', 'height', 'allowfullscreen', 'frameborder', 'start', 'end'],
img: [...xss.whiteList.img, 'usemap'],
img: [...xss.whiteList.img, 'usemap', 'style'],
map: ['name'],
area: [...xss.whiteList.a, 'coords'],
a: [...xss.whiteList.a, 'rel'],
td: [...xss.whiteList.td, 'style'],
th: [...xss.whiteList.th, 'style'],
},
css: {
whiteList: {
'image-rendering': /^pixelated$/,
'text-align': /^center|left|right$/,
},
},
onIgnoreTagAttr: (tag, name, value) => {
Expand Down Expand Up @@ -50,12 +53,14 @@ export const configuredXss = new xss.FilterXSS({
}

// For Highlight.JS
if (
name === 'class' &&
['pre', 'code', 'span'].includes(tag) &&
(value.startsWith('hljs-') || value.startsWith('language-'))
) {
return name + '="' + xss.escapeAttrValue(value) + '"'
if (name === 'class' && ['pre', 'code', 'span'].includes(tag)) {
const allowedClasses = []
for (const className of value.split(/\s/g)) {
if (className.startsWith('hljs-') || className.startsWith('language-')) {
allowedClasses.push(className)
}
}
return name + '="' + xss.escapeAttrValue(allowedClasses.join(' ')) + '"'
}
},
safeAttrValue(tag, name, value, cssFilter) {
Expand Down