Skip to content

Unexpected closing tag in html condition comments #5426

@akronb

Description

@akronb

Prettier 1.15.1
Playground link

--parser html

Input:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title></title>
  </head>

  <body width="100%" align="center">
    <center>                                        
      <!--[if (gte mso 9)|(IE)]><table cellpadding="0" cellspacing="0" border="0" width="600" align="center"><tr><td><![endif]-->
      <div></div>
      <!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->
    </center>
  </body>
</html>

Output:

SyntaxError: Unexpected closing tag "td". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (12:32)
  10 |       <!--[if (gte mso 9)|(IE)]><table cellpadding="0" cellspacing="0" border="0" width="600" align="center"><tr><td><![endif]-->
  11 |       <div></div>
> 12 |       <!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->
     |                                ^
  13 |     </center>
  14 |   </body>
  15 | </html>

Expected behavior:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title></title>
  </head>

  <body width="100%" align="center">
    <center>                                        
      <!--[if (gte mso 9)|(IE)]><table cellpadding="0" cellspacing="0" border="0" width="600" align="center"><tr><td><![endif]-->
      <div></div>
      <!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->
    </center>
  </body>
</html>

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.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions