Hugo template formatting in VS Code

房东的猫 提交于 2020-02-25 01:35:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!