NiklasPor / prettier-plugin-go-template

Fixes prettier formatting for go templates 🐹
prettier-plugin-go-template-niklaspor.vercel.app
MIT License
343 stars 24 forks source link

prettier-ignore comments don't work for html fragments #94

Open josharian opened 2 years ago

josharian commented 2 years ago

We have a series of templates that are used to render headers and footers piecemeal. They contain mismatch html tags, by design.

I figured we could work around this by using ignore comments. However, this doesn't work.

{{/* prettier-ignore-start */}}
</head>
{{/* prettier-ignore-end */}}

This yields:

Error: An error occured during printing. Found invalid node block.

NiklasPor commented 2 years ago

Yep, as you probably figured out, mismatched HTML tags are currently a problem as the parser is just a derivation from the regular HTML parser with additions.

josharian commented 2 years ago

Yep. :)

The thing I was surprised by here is that the ignore comments didn’t resolve the problem—I guess I expected them to cause the intervening contents to be completely skipped during the analysis.

nikwen commented 1 year ago

For anyone else stumbling across this:

If you have a comment that you don't want prettier to format, do the following:

{{/* prettier-ignore-start */}}
{{/*
      my multiline comment with
         weird indentation
               that prettier would destroy
*/}}
{{/* prettier-ignore-end */}}

The following will not work:

{{/* prettier-ignore */}}
{{/*
      my multiline comment with
         weird indentation
               that prettier would destroy
*/}}