NiklasPor / prettier-plugin-go-template

Fixes prettier formatting for go templates 🐹

Home Page:prettier-plugin-go-template-niklaspor.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syntax error: unexpected closing tag - issue with escaped strings in printf?

gcushen opened this issue · comments

commented

Problem

The following valid Hugo snippet

      {{ if $load }}
        {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\" async></script>" (printf $v.url $v.version) $v.sri | safeHTML }}
      {{ end }}

results in the plugin incorrectly exiting with a SyntaxError:

SyntaxError: Unexpected closing tag "script". 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

Version: 0.0.10

I can provide the full context if needed for reproduction of the issue.

Analysis

The Hugo snippet runs fine in Hugo and appears to be a valid Go HTML Template.

Possible issue with formatter parsing HTML within Hugo's printf? Perhaps an issue with how the plugin handles escaped strings?

Hi, #49 will resolve this 🚀

Output without error:

{{ if $load }}
  {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\" async></script>" (printf $v.url $v.version) $v.sri | safeHTML }}
{{ end }}