Open wajeshubham opened 2 years ago
@wajeshubham Fixed this, but not perfect.
Ok thanks @jaywcjlove
@jaywcjlove I'm still facing a highlighting issue for code
Please let me know if I'm missing something.
export const MdComp: React.FC<Props> = ({ source, className }) => {
return (
<MDEditor.Markdown
className={className}
source={source}
rehypePlugins={[[rehypeSanitize]]}
linkTarget="_blank"
/>
);
};
import React from "react";
import ReactDOM from "react-dom";
import MDEditor from "@uiw/react-md-editor";
// No import is required in the WebPack.
// import "@uiw/react-md-editor/dist/markdown-editor.css";
const mkdStr = `# Markdown Editor for [React](https://facebook.github.io/react/)
**Hello world!!!**
[![](https://avatars.githubusercontent.com/u/1680273?s=80&v=4)](https://avatars.githubusercontent.com/u/1680273?v=4)
\`\`\`javascript
import React from "react";
import ReactDOM from "react-dom";
import MEDitor from '@uiw/react-md-editor';
\`\`\`
\`\`\`jsx
export const MdComp: React.FC<Props> = ({ source, className }) => {
return (
<MDEditor.Markdown
className={className}
source={source}
rehypePlugins={[[rehypeSanitize]]}
linkTarget="_blank"
/>
);
};
\`\`\`
`;
function App() {
return (
<div className="container">
<MDEditor.Markdown
style={{ padding: 15 }}
source={mkdStr}
linkTarget="_blank"
// previewOptions={{
// linkTarget: "_blank"
// }}
/>
</div>
);
}
Removing rehypePlugins
prop resolves the issue. But isn't it insecure? do you have any other secure way for the same?
import React from "react";
import ReactDOM from "react-dom";
import MDEditor from "@uiw/react-md-editor";
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
// No import is required in the WebPack.
// import "@uiw/react-md-editor/dist/markdown-editor.css";
const mkdStr = `# Markdown Editor for [React](https://facebook.github.io/react/)
**Hello world!!!**
[![](https://avatars.githubusercontent.com/u/1680273?s=80&v=4)](https://avatars.githubusercontent.com/u/1680273?v=4)
\`\`\`javascript
import React from "react";
import ReactDOM from "react-dom";
import MEDitor from '@uiw/react-md-editor';
\`\`\`
\`\`\`jsx
export const MdComp: React.FC<Props> = ({ source, className }) => {
return (
<MDEditor.Markdown
className={className}
source={source}
rehypePlugins={[[rehypeSanitize]]}
linkTarget="_blank"
/>
);
};
\`\`\`
`;
function App() {
return (
<div className="container">
<MDEditor.Markdown
style={{ padding: 15 }}
source={mkdStr}
linkTarget="_blank"
// rehypePlugins={[[rehypeSanitize]]}
pluginsFilter={(type, plugin) => {
if (type === "rehype") {
// plugin.push(rehypeSanitize);
plugin.unshift([
rehypeSanitize,
{
...defaultSchema,
attributes: {
...defaultSchema.attributes,
code: [
...(defaultSchema.attributes.code || []),
// List of all allowed languages:
[
"className",
"language-jsx",
"language-javascript",
"language-jsx",
"language-js",
"language-css",
"language-md"
]
]
}
}
]);
console.log(plugin);
}
return plugin;
}}
// previewOptions={{
// linkTarget: "_blank"
// }}
/>
</div>
);
}
Thanks @jaywcjlove. Last question, how much secure is the rehypen plugin? Do we need to use something like dompurify
to stay away from the XSS attacks? or rehypen plugin is alone secure to do so?
I'm not sure how safe it is, you can ask here: https://www.npmjs.com/package/rehype-sanitize
@wajeshubham
While using
code
snippet syntax in editor and trying to edit extension text beside"```"
I'm getting following error:This happens when user try to edit
"```jsx"
part inside the editor:Also the code snippets are not getting highlighted in my markdown preview.
NOTE: Your own website is also crashing due to the same issue.Kindly open https://uiwjs.github.io/react-md-editor/ and try to edit the following part:
https://user-images.githubusercontent.com/62889697/173334753-23d79d78-cdca-4d23-9c8b-eb2abe9220fe.mp4