Trying to understand how rehypeReact inserts custom React nodes #128
-
I am parsing some Markdown and I want to include a custom React component. I am using this: .use(rehypeReact, {
createElement,
Fragment,
components:{
test:()=><div>Testing...</div>
}}) My markdown looks like this:
The HTML that is generated is <p><div>Testing...</div></p>
<p>After 1</p>
<div>Testing...</div> So, if I use open and close tags, the component is wrapped in a paragraph tag. If I use a self-closing tag, it appears to be inserted as a fragment without the wrapping, BUT nothing after the tag in the markdown is included. I am trying to put a component that includes elements that should not be inside of a Am I doing something wrong, or have I uncovered a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Welcome @ChristopherPAndrews! 👋
|
Beta Was this translation helpful? Give feedback.
Welcome @ChristopherPAndrews! 👋
Yes, the behavior is expected, it's how HTML works.
An example with
<div>
which illustrates what the expected behavior is:https://html.spec.whatwg.org/multipage/parsing.html#parse-error-non-void-html-element-start-tag-with-trailing-solidus
<test/>
is not self closing (these exist in XML, not in HTML) nor is it a void element in HTML.