jsx-to-string
jsx-to-string copied to clipboard
Adds incorrect whitespace to output (needs "no-format" option)
If you pass this JSX string:
<p><em className="bar">foo</em>or<strong>baz</strong></p>
You get this output:
<p>
<em className='bar'>
foo
</em>
or
<strong>
baz
</strong>
</p>
This will add whitespace between the em
, "or" and strong
, which is incorrect. If you use ReactDOMServer.renderToStaticMarkup
, you get this, which is correct:
<p><em class="bar">foo</em>or<strong>baz</strong></p>
This could be resolved by a noformat
or similar option, which removed indentation and newlines in the output.
I like the idea of having a format: false
option. Are you up for a pull request on that one?
I'm not sure when I will have time to address this request.
Thanks for the reply!
So, I wrote a PR, but then realized that I misconstrued slightly in that this issue is predicated on the output of the function being HTML. In my use case, I have JSX without Components, which I need to render to HTML cheaply (without bringing on renderToStaticMarkup
).
However, the output of this function is JSX, which means that the whitespace no longer matters in the same sense. So I'm inclined to close this, unless you disagree with my assessment above.