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

Svelte trims content for <pre> #6437

Closed
lega911 opened this issue Jun 24, 2021 · 5 comments · Fixed by #6990
Closed

Svelte trims content for <pre> #6437

lega911 opened this issue Jun 24, 2021 · 5 comments · Fixed by #6990

Comments

@lega911
Copy link

lega911 commented Jun 24, 2021

Describe the bug
Considering specs "pre" should display content as is, https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
But Svelte trims content

To Reproduce
https://svelte.dev/repl/829574eb0d814385b6842c7a4ba000dc?version=3.38.3

@babakfp
Copy link
Contributor

babakfp commented Jun 25, 2021

Check out this REPL
I don't know anything about Svelte core but if you are having this issue in your current project and you want to solve it quickly as possible, just check out the repl.
It seems that something is wrong with the first character(or group of character or a line) that goes into the <pre> tag maybe🤷‍♂️

@AviFS
Copy link

AviFS commented Aug 14, 2021

Check out this REPL

This is a perfect fix! I wonder why this isn't the default behavior, though. Does someone mind shedding some light on this? Bug or feature?

@Mlocik97
Copy link
Contributor

Mlocik97 commented Aug 14, 2021

it's interesting that simple empty span fix trimming. I saw already similiar bug with more ifs in row, where adding one space in code fixed padding by 200px.

dummdidumm pushed a commit that referenced this issue Feb 2, 2022
Fixes #6437
Fixes #4731
Closes #4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
@Conduitry
Copy link
Member

@pablo-abc
Copy link

This took me a bit by surprise on my site (I updated too many packages at once so I didn't realise it was due to Svelte). My mistake since I was relying on the non-standard behaviour by doing this:

  <pre class="{`prism language-${lang}`}" tabindex="0">
    <code class=prism>{@html code}</code>
  </pre>

Switching to this solves it (and it is how it should be I guess?):

  <pre
    class="{`prism language-${lang}`}"
    tabindex="0"
  ><code class=prism>{@html code}</code></pre>

Only one detail. Svelte seems to be adding an extra whitespace when there's a new line at the beginning when this does not happen using plain HTML unless there's an explicit white space after the <pre> tag.

himanshiLt pushed a commit to himanshiLt/svelte that referenced this issue Mar 3, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
nevilm-lt pushed a commit to nevilm-lt/svelte that referenced this issue Mar 14, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
nevilm-lt pushed a commit to nevilm-lt/svelte that referenced this issue Apr 21, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
nevilm-lt pushed a commit to nevilm-lt/svelte that referenced this issue Apr 21, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
nevilm-lt pushed a commit to nevilm-lt/svelte that referenced this issue Apr 22, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
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.

6 participants