Shopify / prettier-plugin-liquid

Prettier Liquid/HTML plugin
https://npm.im/@shopify/prettier-plugin-liquid
MIT License
93 stars 15 forks source link

LiquidHTMLParsingError on doctype declaration #96

Closed albchu closed 1 year ago

albchu commented 2 years ago

Describe the bug When I plug in the unformatted source below into the playground, I encounter an unexpected error.

Unformatted source

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="{{ locale }}" dir="{{ direction }}" class="{{ checkout_html_classes }}">
<head>
 <meta charset="utf-8">
</head>
<body>
Some body
</body>
</html>

Expected output

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="{{ locale }}" dir="{{ direction }}" class="{{ checkout_html_classes }}">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    Some body
  </body>
</html>

Actual output

LiquidHTMLParsingError: Line 1, col 23: expected ">", "/", not (a space or a quotes or "=" or ">" or "/" or "{{" or "{%" or a controls or a noncharacters), "{%", "{{", or "="
> 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    |                       ^
  2 | <html lang="{{ locale }}" dir="{{ direction }}" class="{{ checkout_html_classes }}">
  3 |   <head>
  4 |     <meta charset="utf-8">
    at toLiquidHtmlCST (https://www.unpkg.com/@shopify/prettier-plugin-liquid@v0.3.1/standalone.js:1197:15)
    at toLiquidHtmlAST (https://www.unpkg.com/@shopify/prettier-plugin-liquid@v0.3.1/standalone.js:480:43)
    at Object.parse (https://www.unpkg.com/@shopify/prettier-plugin-liquid@v0.3.1/standalone.js:1711:38)
    at Object.m [as parse] (https://www.unpkg.com/prettier@2.7.1/standalone.js:40:1354)
    at S (https://www.unpkg.com/prettier@2.7.1/standalone.js:41:15055)
    at D (https://www.unpkg.com/prettier@2.7.1/standalone.js:45:576)
    at https://www.unpkg.com/prettier@2.7.1/standalone.js:116:7304
    at Object.format (https://www.unpkg.com/prettier@2.7.1/standalone.js:116:7395)
    at HTMLTextAreaElement.format (https://shopify.github.io/prettier-plugin-liquid/assets/playground.js:57:29)

Debugging information

Additional context Using "version": "0.3.1" to build prettier formatting into the code editor.

charlespwd commented 2 years ago

Ha. I've definitely took a shortcut on this one. Looks like I'll have to be more spec-compliant :upside_down_smile: