Custom Elements in react-remark #616
-
Hello There. I'm trying to allow my MD to have custom HTML tags which I have react components for. I currently am calling my code like this <MD
remarkToRehypeOptions={{ allowDangerousHtml: true }}
rehypePlugins={[rehypeRaw, rehypeSanitize]}
rehypeReactOptions={{
components: {
// eslint-disable-next-line jsx-a11y/anchor-has-content
a: props => <a className="text-blue-500 hover:text-blue-400 focus:text-blue-400 focus:outline-none" {...props} />,
Button: props => <Button {...props} />
},
}}
>{this.state.value}</MD> My markdown is this ## Hello there!
This is a test page.
<Button>Click Me!</Button> I want the Button tag in my MD to render to my button class in React. Is there a way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Depends on the exact behavior you want. |
Beta Was this translation helpful? Give feedback.
-
I have just created a plugin to solve this issue. It uses the remark-directive pattern so that |
Beta Was this translation helpful? Give feedback.
Depends on the exact behavior you want.
HTML will map both
<button>
and<Button>
(and all other upper and lowercase combinations) tobutton
, and if that's what you're looking forrehypeReactOptions
should work fine.If you want to differentiate between
<button>
and<Button>
, then you want JSX in markdown instead of HTML in markdown, which is where MDX (also built on remark) could help https://mdxjs.com/advanced/runtime