diff --git a/README.md b/README.md index 660e2148..02f72464 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ This [`ReactMarkdownProps`](https://github.com/remarkjs/react-markdown/tree/02ba Markdown to parse - `className` (`string?`)\ Wrap the markdown in a `div` with this class name -- `skipHtml` (`boolean`, default: `false`)\ +- `skipHtml` (`boolean`, default: ~~`false`~~ -> [`true`](https://github.com/uiwjs/react-markdown-preview/issues/205) )\ Ignore HTML in Markdown completely - `sourcePos` (`boolean`, default: `false`)\ Pass a prop to all components with a serialized position diff --git a/package.json b/package.json index 483c4f57..56d6c596 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "rehype-autolink-headings": "~6.1.1", "rehype-ignore": "^1.0.1", "rehype-prism-plus": "~1.5.0", + "rehype-raw": "^6.1.1", "rehype-rewrite": "~3.0.6", "rehype-slug": "~5.0.1", "remark-gfm": "~3.0.1", diff --git a/src/index.tsx b/src/index.tsx index ac1bbcc6..39e497a0 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,6 +3,7 @@ import ReactMarkdown, { Options } from 'react-markdown'; import { Element } from 'hast'; import { PluggableList } from 'unified'; import gfm from 'remark-gfm'; +import raw from 'rehype-raw'; import slug from 'rehype-slug'; import headings from 'rehype-autolink-headings'; import rehypeAttrs from 'rehype-attr'; @@ -41,6 +42,7 @@ export default React.forwardRef((props source, style, disableCopy = false, + skipHtml = true, onScroll, onMouseOver, pluginsFilter, @@ -85,12 +87,16 @@ export default React.forwardRef((props return /^[A-Za-z0-9]+$/.test(element.tagName); }, }; + if (skipHtml) { + rehypePlugins.push(raw); + } const remarkPlugins = [...(other.remarkPlugins || []), gfm]; return (
{ spellCheck="false" onChange={(e) => setValue(e.target.value)} /> - +
/, '')} />