Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespace issue after a tag #159

Closed
mcmxcdev opened this issue Nov 8, 2020 · 6 comments · Fixed by #173
Closed

Whitespace issue after a tag #159

mcmxcdev opened this issue Nov 8, 2020 · 6 comments · Fixed by #173

Comments

@mcmxcdev
Copy link

mcmxcdev commented Nov 8, 2020

Describe the bug
Might be related to prettier-plugin-svelte, but I am having this issue since a long time.

In the first example in the REPL provided below, there is no white space as expected, in the 2nd example the tag opening and closing tag and the text are all on individual lines (like prettier formats it) and it seems to count as a white space.

To Reproduce
https://svelte.dev/repl/6eca3f26aee1427580c9781c0e3396a5?version=3.29.4

Expected behavior
No white space no matter how the code is formatted.

Information about your Svelte project:

  • Your browser and the version: Brave 1.16.72

  • Your operating system: Ubuntu Linux 20.10

  • Svelte version: 3.29.4

  • Whether your project uses Webpack or Rollup

@dummdidumm
Copy link
Member

I would say this is the correct behavior since the a tag is white space sensitive. This is a bug with the prettier formatter then.

@mcmxcdev
Copy link
Author

mcmxcdev commented Nov 8, 2020

@dummdidumm I see, can you move the issue to prettier-plugin-svelte?

@dummdidumm dummdidumm transferred this issue from sveltejs/svelte Nov 8, 2020
@dummdidumm
Copy link
Member

The bug is: the text should "hug" the start/end tags and not add line breaks/whitespace.
@ehrencrona before you jump in, I have a little rework of the children logic in the making which might also deal with this.

@ehrencrona
Copy link
Contributor

So the bug is that the second <p> in the REPL formats to the first? Isn't the issue that the formatter would need to know whether the component is whitespace sensitive or not? We discussed this in #28 where we talked about using prettier-ignore or <!-- display: block --> for these situations.

I'm a bit confused by the whitespace being present in the output after the body ("...coffee") but not before it ("buy me..."). I remember the Svelte parser doing trimming somewhere but I'm not sure in which circumstances.

@dummdidumm let me know when the refactoring is done and if i can help at that point. I'll hold off until then.

@dummdidumm
Copy link
Member

Oh right, I forgot about #28 . Prettier treats everything as whitespace sensitive except the block elements. Maybe we should do the same and switch it up. Right now everything is treated as a block except a specified list of inline-elements.

@mcmxcdev
Copy link
Author

mcmxcdev commented Dec 3, 2020

Is there any progress on this issue? I am writing a lot of content right now which is wrongly formatted unfortunately, would be great to get this resolved.

dummdidumm pushed a commit to dummdidumm/prettier-plugin-svelte that referenced this issue Jan 2, 2021
Fixes sveltejs#159

### BREAKING CHANGE
Components were treated as block elements before. Treat them as inline elements now (safer default behavior) by switching the logic: Everything that's part of the list of block elements is a inline element.
dummdidumm added a commit that referenced this issue Jan 2, 2021
Fixes #159

### BREAKING CHANGE
Components were treated as block elements before. Treat them as inline elements now (safer default behavior) by switching the logic: Everything that's part of the list of block elements is a inline element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants