-
-
Notifications
You must be signed in to change notification settings - Fork 140
Fix <script> and <style> parsing #19
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Current behavior:
var Parser = require('html-react-parser');
Parser('<script>1 < 2;</script>'); // works
Parser('<script></script>'); // returns `[]`
Parser('<style></style>'); // does not workThe error stems from the flawed logic here. The if-check for node.children[0] needs to be separated and there needs to be a check for style tag as well.
React's Dangerously Set innerHTML needs to be used for setting style content (similar to script) to prevent CSS from being escaped.
var React = require('react');
var render = require('react-dom/server').renderToStaticMarkup;
render(React.createElement('style', {}, 'div > p { font-family: "Open Sans"; }'));
// '<style>div > p { font-family: "Open Sans"; }</style>'Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working