jsx-to-string icon indicating copy to clipboard operation
jsx-to-string copied to clipboard

Adds incorrect whitespace to output (needs "no-format" option)

Open giles-v opened this issue 7 years ago • 2 comments

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.

giles-v avatar Mar 07 '17 14:03 giles-v

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.

alansouzati avatar Mar 07 '17 21:03 alansouzati

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.

giles-v avatar Mar 07 '17 21:03 giles-v