-
-
Notifications
You must be signed in to change notification settings - Fork 134
trim option should exclude <pre> #205
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Thanks for the idea @danielimmke! Unfortunately, it's not easy to preserve whitespace inside a For example, how can we handle the following? const parse = require('html-react-parser');
parse(`
<pre>
hello <em>world <span>!</span> </em>
</pre>
`, { trim: true }); html-dom-parser will parse each element ( const { htmlToDOM } = require('html-react-parser');
htmlToDOM(`
<pre>
hello <em>world <span>!</span> </em>
</pre>
`); See Repl.it demo. |
Thanks for the quick reply - maybe there's a better more generic way to handle this then. I still need to do I'm using this inside a Gatsby project and |
Actually there is a way to disable import parse, { domToReact } from 'html-react-parser';
const html = `
<pre>
<span>Whitespace is
<strong>preserved</strong>!
</span>
</pre>
`;
const options = {
replace: ({ name, children }) => {
if (name === 'pre') {
return domToReact(children, options);
}
},
};
parse(html, { ...options, trim: true }); See CodeSandbox demo. |
Thanks, I will try that instead. |
Uh oh!
There was an error while loading. Please reload this page.
Thank you for the project. Is it possible to have the
trim: true
option ignore everything inside<pre>
elements given the nature of that element is to preserve whitespace? Would your merge a PR that does this?The text was updated successfully, but these errors were encountered: