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

Investigate HTML whitespace changes during parse/stringify #1

Open
TheJaredWilcurt opened this issue Dec 26, 2021 · 1 comment
Open
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@TheJaredWilcurt
Copy link
Member

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:

  • Not passing in proper settings to the parsing step
  • Not passing in proper settings to the stringify step
  • Something during the modification of the AST

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 TheJaredWilcurt added enhancement New feature or request help wanted Extra attention is needed labels Dec 26, 2021
@TheJaredWilcurt
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: Backlog
Development

No branches or pull requests

1 participant