Skip to content

Unexpected formatting for script tag #6393

@pikeas

Description

@pikeas

Prettier 1.18.2
Playground link

--html-whitespace-sensitivity strict
--parser html

Input:

<html>
  <body>
    <script
      async=""
      id=""
      src="/_next/static/development/pages/_app.js?ts=1565732195968"
    ></script><script></script>
  </body>
</html>

Output:

<html>
  <body>
    <script
      async=""
      id=""
      src="/_next/static/development/pages/_app.js?ts=1565732195968"
    ></script
    ><script></script>
  </body>
</html>

Expected behavior:

There are several previous GH issues about HTML whitespacing sensitivity, which seem to be related to this but not quite the same. There's also https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting.

For the above input, the output for css and strict are the same. For this case, prettier adds an extra newline for </script><script></script>, and borrows the closing > while doing so.

This looks like an incorrect result. I expected either <script></script> on a newline (without the borrowed >), or for the input HTML to remain unmodified (when using strict).

This output is also problematic for syntax highlighters. You can see this happening in Github's highlighting for the text above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:htmlIssues affecting HTML (and SVG but not JSX)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions