Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit e84c5d4

Browse files
committed
refactor(helpers): clean up markdown sanitization
sanitize-html actually does not support regexes and the fact that it worked is a bug. See apostrophecms/sanitize-html#253
1 parent dd2d93b commit e84c5d4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/helpers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,13 @@ export const renderMarkdown = (markdown: string): string => {
9999
highlight: (code, language) => highlightCodeSafe(code, language),
100100
})
101101
return sanitize(rendered, {
102+
// Allow highligh.js styles, e.g.
103+
// <span class="hljs-keyword">
104+
// <code class="language-javascript">
102105
allowedTags: [...sanitize.defaults.allowedTags, 'span'],
103-
allowedClasses: {
104-
'*': [/^hljs-.+/ as any],
106+
allowedAttributes: {
107+
span: ['class'],
108+
code: ['class'],
105109
},
106110
})
107111
}

0 commit comments

Comments
 (0)