Closed RARgames closed 7 months ago
@RARgames Some plugins are built in by default, which may be caused by them.
You can use pluginsFilter to clear out the default plugins, or put rehype-sanitize
at the front of the array and give it a try.
@jaywcjlove I just finished testing it. Plugins seem not to change affect this. (using filters I removed all plugins and the issue still exists)
Extended test (customized version of react-markdown-preview
without extra plugins and updated dependencies):
I removed rehype, remark plugins from react-markdown-preview
. Also I updated react-markdown
.
Final dependencies:
"dependencies": {
"@babel/runtime": "^7.17.2",
"@uiw/copy-to-clipboard": "~1.0.12",
"react-markdown": "~9.0.1",
"unist-util-visit": "^4.1.0"
}
Unfortunately, this doesn't fix the issue:
Do you have any other ideas of what might be causing it?
https://codesandbox.io/embed/sharp-mountain-m7yx7t?fontsize=14&hidenavigation=1&theme=dark
@RARgames You may need to look for answers in the issues of rehype-sanitize and react-markdown. The above example tells me that the problem does not occur on our side.
@RARgames If you solve it, you can tell us and I will update it in the document, thank you🙏
This is the example that works: https://codesandbox.io/s/vigilant-williams-glfmzy?fontsize=14&hidenavigation=1&theme=dark
import Markdown from "react-markdown";
import rehypeSanitize from "rehype-sanitize";
import rehypeRaw from "rehype-raw";
const source = `
## MarkdownPreview
**Hello world!!!** <IFRAME SRC=\"javascript:javascript:alert(window.origin);\"></IFRAME>
<!-- test --> 123
<!-- test --> 456 <!-- test -->
`;
const rehypePlugins = [rehypeRaw, rehypeSanitize];
export default function App() {
return (
<div className="App">
<Markdown rehypePlugins={rehypePlugins}>{source}</Markdown>
</div>
);
}
Outdated - left here just for history
~~However using rehypeRaw
in this place breaks code blocks - there is an error.
The error can be fixed by additionally using:~~
const remarkPlugins = [remarkParse, [remarkRehype, { allowDangerousHtml: true }]];
There is no error, but code blocks does not show correctly. To fix this we need the order of rehype/remark plugins (not sure).
Here is the final fix:
rehype-raw
in front of rehypePlugins list (https://github.com/uiwjs/react-markdown-preview/blob/master/core/src/index.tsx)rehype-sanitize
as usualI can prepare a PR, but this requires a bit more knowledge (I did this while testing and it seems to work fine).
node.data
and node.data.meta
to node.properties
and node.properties.meta
?if (skipHtml) rehypePlugins.push(raw)
(https://github.com/uiwjs/react-markdown-preview/blob/master/core/src/preview.tsx). This might have some conflicts with rehype-raw
as now it is used always. Please check this.Created a PR. The points from the previous comment are valid. I'll prepare and post custom schema later.
highlight line
and Show Line Numbers
does not work because of the rehypeRaw
.
Probably, it's again the order of rehype, remark plugins. I'm trying to fix this right now, but without success.
rehype-raw
: rehype-sanitize
does not work correctlyrehype-raw
: rehype-prism-plus
does not highlight/show lines@RARgames This may require rehype-prism-plus
to upgrade dependency packages
@jaywcjlove I already checked it - updating dependencies does not help.
However, I've managed to create a fix in the test env.
I'll try to implement it in react-markdown-preview
and submit another PR.
I'll let you know here when it's ready (Also please bump react-markdown-preview
in react-md-editor
after the PR).
@RARgames 👌
@RARgames Upgrade v4.0.0
I'm just using rehype-sanitize (with default schema, no other rehype/remark plugins for this tests). Pure rehype-sanitize works correctly, but when it's applied on top of react-md-editor it has an issue with comments.
I cannot track down what is causing the issue, but here is the example:
input:
output github/pure rehype-sanitize (Sandbox: https://stackblitz.com/edit/github-ozn1qm?file=src%2Fmain.ts ):
123 456
output using rehype-sanitize on top of react-md-editor: emptyFrom debugging using visit somehow
<!-- test --> 456 <!-- test -->
is treated as one object of typeraw
instead of 3 separate objects:<!-- test -->
,456
,<!-- test -->
.My example (just the important parts):
You can also test it in your demo: