-
|
How do I safely combine markdown, remark-math with rehype-santize and rehype-raw? The default schema doesn't allow for svg. Something like this keeps the SVG from being rendered. <ReactMarkdown
children="$$x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$$"
rehypePlugins=[rehypeMathJax, rehypeRaw, [rehypeSanitize, defaultSchema]],
remarkPlugins: [RemarkMathPlugin]
/>Maybe I could go through and whitelist the different svg elements and attributes in the rehype-sanitize schema like this: const santizeSchema = {
...defaultSchema,
tagNames: [
...defaultSchema.tagNames,
'svg',
'defs',
'path',
'mjx-container',
'g',
'rect',
'use',
],
attributes: {
...defaultSchema.attributes,
span: ['style', 'className'],
div: ['className'],
svg: ['xmlns', 'focusable', 'width', 'height', 'style', 'role', 'viewBox', 'xmlns:xlink'],
path: ['id', 'd'],
'mjx-container': ['jax', 'className', 'display'],
'g': ['stroke', 'fill', 'transform', 'stroke-width', 'data*'],
'rect': ['width', 'height', 'x', 'y'],
'use': ['data*', 'xlink:href', 'xlink']
}
}I haven't had much luck with it. The It'd also be nice to have an approach that doesn't let the user manually enter svg attributes. Ideally the remark and rehype plugins would be the only things able to put svg into the output. But I'll settle for just being able to whitelist the svg elements properly. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi there! SVG is quite dangerous — there are good reasons for why GitHub et all don’t allow it. Also allowing You seem to be trying to allow basically all things in SVG which implies that you trust your content. If that’s the case, than perhaps you could skip this package? |
Beta Was this translation helpful? Give feedback.
Hi there!
SVG is quite dangerous — there are good reasons for why GitHub et all don’t allow it. Also allowing
classNameseverywhere opens you up to attacks.You seem to be trying to allow basically all things in SVG which implies that you trust your content. If that’s the case, than perhaps you could skip this package?