问题
The auto format in VS Code is making my code unreadable by removing indentations. I don't know how to turn this off for handlebars only.
Input:
{{ range ... }}
{{ if .... }}
{{if ... }}
<tag></tag>
{{end}}
{{end}}
{{end}}
Output
{{ range ... }}
{{ if .... }}
{{if ... }}
<tag></tag>
{{end}}
{{end}}
{{end}}
Any way to prevent this?
回答1:
I couldn't find a clean way to do this, but the kludgy work around I found is to use the html.format.contentUnformatted
setting in my workspace with a custom html tag.
"settings": {
"html.format.contentUnformatted": "ignore-format"
}
And then wrap sections of templating code that need formatting inside this tag.
<ignore-format>
{{ range ... }}
{{ if .... }}
{{if ... }}
<tag></tag>
{{end}}
{{end}}
{{end}}
</ignore-format>
Note that I chose ignore-format
, this can be any valid custom html tag name. If you find a cleaner solution, please let me know and I'll mark your answer as accepted.
来源:https://stackoverflow.com/questions/57980680/hugo-template-formatting-in-vs-code