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

HTML whitespace is not maintained. #24

Closed
hperrin opened this issue May 21, 2019 · 9 comments
Closed

HTML whitespace is not maintained. #24

hperrin opened this issue May 21, 2019 · 9 comments
Labels
bug Something isn't working

Comments

@hperrin
Copy link

hperrin commented May 21, 2019

Wrapping a word just before punctuation, but not wrapping the punctuation, results in bad formatting.

<p>This is a <strong>bold stance</strong>.</p>

becomes

<p>
  This is a
  <strong>bold stance</strong>
  .
</p>

Which is rendered as:

This is a bold stance .

Notice the space before the period.

@jamesbirtles jamesbirtles added the bug Something isn't working label May 23, 2019
@RedHatter
Copy link

RedHatter commented May 24, 2019

One work around for this issue is to use a markup preprocessor on compilation to remove all white-space.

    svelte({
      preprocess: {
        markup: input => ({
          code: input.content
            .replace(/(>|})\s+(?![^]*?<\/(?:script|style)>|[^<]*?>|[^{]*?})/g, '$1')
            .replace(/(?<!<[^>]*?|{[^}]*?)\s+(<|{)(?![^]*<\/(?:script|style)>)/g, '$1')
        })
      },
      css: css => css.write('dest/devtools/styles.css'),
    })

The RegExs are't as scary as they look. They replace any white-space preceding a { or < and any white-space following a } or > provided the white-space don't occur inside of a script tag, style tag, inline javascript expression, or html tag opening/closing.

@jarrodldavis
Copy link
Contributor

Hey @hperrin, I've begun working on fixing this in #41. Please let me know if you think this is an adequate fix.

@happycollision
Copy link

happycollision commented Feb 4, 2020

Ugh. I tried to take over #41 by cloning, but I cannot figure it out quickly enough to be worthwhile.

@terrygonguet
Copy link

This is still a problem and #41 seems to have been abandonned...
Similarly to @happycollision I tried to jump into it but there's too much to take in alone.
However this particular issue seems to have been fixed at some point in #41, could we not "just" get that part merged into master? I understand the other goals of the PR are important too but why not use a fix we already have?

@happycollision
Copy link

That was my original intent: to fork and just do a smaller PR, but even the state that it was in already did not seem to fix the inline element whitespace issue.

@louisabraham
Copy link

Hi, I have the same problem even with option --html-whitespace-sensitivity=strict

@elbertwang3
Copy link

also having this issue. are there any workarounds?

@vrde
Copy link

vrde commented Jun 23, 2020

Hi, unfortunately this makes the plugin unusable 😢 any plan to address this?

@ehrencrona
Copy link
Contributor

My PR #116 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
10 participants