Skip to content

Instantly share code, notes, and snippets.

@jonathaningram
Created April 25, 2017 22:13
Show Gist options
  • Save jonathaningram/2457b3339c44a64fceafc54517dc9ff1 to your computer and use it in GitHub Desktop.
Save jonathaningram/2457b3339c44a64fceafc54517dc9ff1 to your computer and use it in GitHub Desktop.
Visual Studio Code formats Go HTML templates and causes the handlebar snytax to become invalid

In actual.html you can see that at line 6 some predicates have been pushed onto a new line which is not a valid Go html/template (causes error template: master:6: unclosed action).

I guess the Code HTML formatter is just treating the handlebars as a plain text node and honouring the max line length, but is it possible for the formatter to see that it's inside handlebars and not touch it?

<!doctype html>
<html>
<body>
{{if and .user.HasThis .user.HasThat .user.HasIt .user.HasThem .user.HasThose .user.HasStuff .user.HasFeels .user.HasThat
.user.HasThis}} (.user.HasThat)}}
<div>They have stuff.</div>
{{end}}
</body>
</html>
<!doctype html>
<html>
<body>
{{if and .user.HasThis .user.HasThat .user.HasIt .user.HasThem .user.HasThose .user.HasStuff .user.HasFeels .user.HasThat .user.HasThis}}
<div>They have stuff.</div>
{{end}}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment