Line breaks in block-level JSX create unexpected whitespace in the output
See original GitHub issueSubject of the issue
As we’re trying to improve Prettier’s support of MDX, I’m trying to understand its syntax better. So far it looked like block-level JSX is supposed to be 100% React-compatible for it to be possible to copy-paste React code from JS to MDX (also it would allow Prettier to use the same code for formatting JSX that it uses for JSX in JS). But I found an incompatibility that breaks this use case, namely: a line break between an element and text doesn’t create whitespace in the output in React but does in MDX. Posting here after asking on Spectrum.
Your environment
The official playground https://mdxjs.com/playground/
Steps to reproduce
<b>foo</b>
bar
Expected behaviour
Should be rendered as
foobar
https://codepen.io/thorn0/pen/NWWEaoo
Actual behaviour
Is rendered as
foo bar
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How can I insert a line break into a <Text> component in ...
Easier in my opinion, because you don't have to insert stuff within the string; just wrap it once and it keeps all your...
Read more >How whitespace is handled by HTML, CSS, and in the DOM
Whitespace is any string of text composed only of spaces, tabs or line breaks (to be precise, CRLF sequences, carriage returns or line...
Read more >kramdown Syntax
Any line that just contains white space characters such as spaces and tabs is considered a blank line by kramdown. One or more...
Read more >Create Line Breaks Without Having to Use br in HTML
The 'content' property describes the stuff we want injected into the span. The white-space property tells us if we are to preserve the ......
Read more >Changelog | Stylelint
Fixed: inconsistent trailing newlines in CLI error output (#4876). ... Removed: styled and jsx syntax options that were replaced with css-in-js in v9.10.0 ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
forgot to mention it here, but this landed for v2, on the
next
branchHi all! I’m going to close this as it landed on the
main
, the (now default) branch we’re using to gear up to the MDX@2 release.The reason is so that it’s more clear which issues still need to be solved already and don’t require further work.
Expect another
next
release soonish, which might include it, or maybe it’s already released as a beta!For more info, see https://github.com/mdx-js/mdx/issues/1041.