You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That's not the point I'm making. The warning that <html> cannot appear as a child of <div> is for when it's actually rendered in browser. But the bug I'm pointing out here is when it's parsed by html-react-parser, before it's even rendered by the browser.
I'm using the replace function in HTMLReactParserOptions to replace out the html tag, but it's not working for this specific case.
For reference, parse('<html><body><p>Hello, World!</p></body></html>') does work but parse('<html><p>Hello, World!</p></html>') doesn't. See this demo
Hmm perhaps I am misunderstanding something @harryzcy, but your demo seems to be working correctly? I inspected the console output and it is rendering html > body > p and text
My demo is the working example that has parse('<html><body><p>Hello, World!</p></body></html>'). Your demo exactly shows when it's not working, when it's parse('<html><p>Hello, World!</p></html>') without the body tag. @remarkablemark
Activity
remarkablemark commentedon Feb 11, 2023
@harryzcy This is expected behavior since if you're trying to render an
<html>tag inside of a root element in a<body>, then you'll get the error:See reproduced demo.
This leads me to the question: are you unable to strip out the
<html>from your string before parsing?harryzcy commentedon Feb 15, 2023
That's not the point I'm making. The warning that
<html> cannot appear as a child of <div>is for when it's actually rendered in browser. But the bug I'm pointing out here is when it's parsed byhtml-react-parser, before it's even rendered by the browser.I'm using the
replacefunction inHTMLReactParserOptionsto replace out thehtmltag, but it's not working for this specific case.For reference,
parse('<html><body><p>Hello, World!</p></body></html>')does work butparse('<html><p>Hello, World!</p></html>')doesn't. See this demoSo I still think it's a bug within the library.
remarkablemark commentedon Mar 4, 2023
Hmm perhaps I am misunderstanding something @harryzcy, but your demo seems to be working correctly? I inspected the console output and it is rendering
html>body>pand textharryzcy commentedon Mar 4, 2023
My demo is the working example that has
parse('<html><body><p>Hello, World!</p></body></html>'). Your demo exactly shows when it's not working, when it'sparse('<html><p>Hello, World!</p></html>')without thebodytag. @remarkablemark