Skip to content

Commit 95f8ba6

Browse files
committedOct 18, 2022
fix: Fix skipHtml does not work. (#205)
1 parent 5213539 commit 95f8ba6

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ This [`ReactMarkdownProps`](https://github.com/remarkjs/react-markdown/tree/02ba
107107
Markdown to parse
108108
- `className` (`string?`)\
109109
Wrap the markdown in a `div` with this class name
110-
- `skipHtml` (`boolean`, default: `false`)\
110+
- `skipHtml` (`boolean`, default: ~~`false`~~ -> [`true`](https://github.com/uiwjs/react-markdown-preview/issues/205) )\
111111
Ignore HTML in Markdown completely
112112
- `sourcePos` (`boolean`, default: `false`)\
113113
Pass a prop to all components with a serialized position

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"rehype-autolink-headings": "~6.1.1",
6262
"rehype-ignore": "^1.0.1",
6363
"rehype-prism-plus": "~1.5.0",
64+
"rehype-raw": "^6.1.1",
6465
"rehype-rewrite": "~3.0.6",
6566
"rehype-slug": "~5.0.1",
6667
"remark-gfm": "~3.0.1",

‎src/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ReactMarkdown, { Options } from 'react-markdown';
33
import { Element } from 'hast';
44
import { PluggableList } from 'unified';
55
import gfm from 'remark-gfm';
6+
import raw from 'rehype-raw';
67
import slug from 'rehype-slug';
78
import headings from 'rehype-autolink-headings';
89
import rehypeAttrs from 'rehype-attr';
@@ -41,6 +42,7 @@ export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props
4142
source,
4243
style,
4344
disableCopy = false,
45+
skipHtml = true,
4446
onScroll,
4547
onMouseOver,
4648
pluginsFilter,
@@ -85,12 +87,16 @@ export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props
8587
return /^[A-Za-z0-9]+$/.test(element.tagName);
8688
},
8789
};
90+
if (skipHtml) {
91+
rehypePlugins.push(raw);
92+
}
8893
const remarkPlugins = [...(other.remarkPlugins || []), gfm];
8994
return (
9095
<div ref={mdp} onScroll={onScroll} onMouseOver={onMouseOver} {...warpperElement} className={cls} style={style}>
9196
<ReactMarkdown
92-
{...other}
9397
{...customProps}
98+
{...other}
99+
skipHtml={skipHtml}
94100
rehypePlugins={pluginsFilter ? pluginsFilter('rehype', rehypePlugins) : rehypePlugins}
95101
remarkPlugins={pluginsFilter ? pluginsFilter('remark', remarkPlugins) : remarkPlugins}
96102
children={source || ''}

‎website/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const App = () => {
3737
spellCheck="false"
3838
onChange={(e) => setValue(e.target.value)}
3939
/>
40-
<MarkdownPreview className="App-editor-preview" source={value} />
40+
<MarkdownPreview skipHtml={false} className="App-editor-preview" source={value} />
4141
</div>
4242
<MarkdownPreview className="App-markdown" source={MDStr.replace(/([\s\S]*)<!--dividing-->/, '')} />
4343
<div className="App-footer">

0 commit comments

Comments
 (0)
Please sign in to comment.