red-perfume / red-perfume-html

Atomizes the classes defined in HTML
https://red-perfume.github.io
MIT License
2 stars 0 forks source link

Investigate HTML whitespace changes during parse/stringify #1

Open TheJaredWilcurt opened 2 years ago

TheJaredWilcurt commented 2 years ago

Some whitespace changes occur from parse5 when we parse the HTML to an AST, modify it, and then convert the AST back to a string.

Example

Input:

<!DOCTYPE html>
<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <p class="cool cow moo">
      Hi there!
    </p>
    <!--
      <span class="dog">comments are skipped</span>
    -->
    <h1 class="cool cat nice wow">
      Meow
    </h1>
    <h2 class="dog">
      Woof
    </h2>
  </body>
</html>

Output:

<!DOCTYPE html><html><head>
    <title>Test</title>
  </head>
  <body>
    <p class="cool moo rp__font-size__--COLON12px rp__padding__--COLON8px">
      Hi there!
    </p>
    <!--
      <span class="dog">comments are skipped</span>
    -->
    <h1 class="cool nice wow rp__font-size__--COLON12px rp__padding__--COLON8px">
      Meow
    </h1>
    <h2 class="rp__font-size__--COLON12px rp__background__--COLON__--OCTOTHORPF00 rp__padding__--COLON8px">
      Woof
    </h2>

</body></html>

This may be caused by our code:

If it is not on our end, then it is a problem with parse5. We would need to either create a PR against parse5 to fix it (it's pretty well written and clean JS). Or find an alternative HTML parser and swap it out.

TheJaredWilcurt commented 2 years ago

Note: I don't really classify this as a bug, since red-perfume should only be used during a build step and markup will likely either already be minified, or will be minified after red-perfume finishes it's modifications. So formatting is less important. But would still rather retain whatever formatting was passed in.