VSCODE - Code formatting in *.hbs files

自古美人都是妖i 提交于 2019-12-23 07:38:16

问题


I have been using VS Code for a while now and I am loving it. But there is a small problem with code formatting. It does not work in handlebars (*.hbs) files. This option is simply unavailable while editing hbs file.

I have tried 'Beautify' extension, but it does not work properly for handlebars - it completely destroys the code.

Any help (or explanation of what am I doing wrong) on that topic would be much appreciated.

EDIT: Same issue applies to *.scss files. Can not format those either.


回答1:


You can click in the bottom right corner on 'Handlebars' and change the language mode to HTML. Then the 'format code' option will be shown.




回答2:


To manually format code:

Let's say the .hbs file we're working on is a .js file.

  • Click the file language option (right side down)

  • Change the file language to .js

  • Click anywhere in the file
  • Press Shift Alt F

To automatically format code on save:

  • Press Ctrl , to open user preferences
  • Enter the following code in the opened settings file

    {
      "editor.formatOnSave": true,
      "html.format.enable": true,
      "html.format.indentHandlebars": true,
      "html.format.maxPreserveNewLines": 0
    }

  • Save file

Source



来源:https://stackoverflow.com/questions/34433915/vscode-code-formatting-in-hbs-files

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