wilsonzlin / minify-html

Extremely fast and smart HTML + JS + CSS minifier, available for Rust, Deno, Java, Node.js, Python, Ruby, and WASM
MIT License
863 stars 37 forks source link

Collapse more whitespaces for formatting elements in content elements #80

Open Rongronggg9 opened 2 years ago

Rongronggg9 commented 2 years ago

Input

<h1>  I  am a title with  <i>  something  italic  </i> and  <a href=https://example.com>  a link  </a>  ! </h1>
<p>
    I am a paragraph with
    <b>
        something bold
    </b>
    and
    <a href=https://example.com>
        a link
    </a>
    !
</p>

Both Chromium and Firefox rendered it like this

minify-html minified it like this

<h1>I am a title with <i> something italic </i> and <a href=https://example.com> a link </a> !</h1><p>I am a paragraph with <b> something bold </b> and <a href=https://example.com> a link </a> !

However, the most minimized HTML should be

-<h1>I am a title with <i> something italic </i> and <a href=https://example.com> a link </a> !</h1><p>I am a paragraph with <b> something bold </b> and <a href=https://example.com> a link </a> !
+<h1>I am a title with <i>something italic </i>and <a href=https://example.com>a link </a>!</h1><p>I am a paragraph with <b>something bold </b>and <a href=https://example.com>a link </a>!

We can verify that they are exactly the same

Ref

https://www.w3.org/TR/CSS2/text.html#white-space-prop

4. If 'white-space' is set to 'normal', 'nowrap', or 'pre-line',
  2. any space (U+0020) following another space (U+0020) — even a
     space before the inline, if that space also has 'white-space'
     set to 'normal', 'nowrap' or 'pre-line' — is removed.

FYI

Python 3.9.12 (main, Mar 24 2022, 13:02:21) [GCC 11.2.0] on linux minify-html 0.8.0

xamgore commented 1 year ago

I double this. I can always put &nbsp; if I need a whitespace symbol. I want to omit all whitespaces from content tags too.