admin 管理员组文章数量: 1086019
I'm using PhpStorm 2016.2 and developing a web application with VueJS.
In PhpStorm I would like reformat HTML code in my JavaScript file. But when I click Code | Reformat
only JavaScript is reformatted.
How to reformat both JavaScript and HTML?
I'm using PhpStorm 2016.2 and developing a web application with VueJS.
In PhpStorm I would like reformat HTML code in my JavaScript file. But when I click Code | Reformat
only JavaScript is reformatted.
How to reformat both JavaScript and HTML?
Share Improve this question edited Jun 18, 2017 at 9:52 LazyOne 166k48 gold badges414 silver badges415 bronze badges asked Jun 18, 2017 at 1:05 Rifton007Rifton007 3711 gold badge7 silver badges25 bronze badges 4- try Ctrl+A to select all. Then Ctrl+Alt+L to format – brk Commented Jun 18, 2017 at 1:06
- Already tried, it does not work.Thank – Rifton007 Commented Jun 18, 2017 at 1:43
-
1
Alt+Enter
while having caret on HTML part and chooseEdit Fragment
(or similarly named entry) from appeared menu. You can then invoke Reformat in separate split. Once done -- just close it (that split). – LazyOne Commented Jun 18, 2017 at 9:53 - Also tried, it does not work, Thank. – Rifton007 Commented Jun 18, 2017 at 22:00
3 Answers
Reset to default 9I found another solution to my problem with PhpStorm 2016. Use the Fragment Editor.
- Place the cursor on your HTML code fragment.
- Press the ALT + ENTER key and click on "Edit HTML Fragment"
- Reformat your html code in the fragment editor.
- Your Javascript file is updated directly.
2016.2 doesn't support formatting HTML injected in Typescript/ECMAScript 6. This feature (WEB-18307) is available since 2017.1, see https://www.jetbrains./help/webstorm/2017.1/using-language-injections.html#d240474e440
Have a look at the Code Style options:
These are my settings and my mixed HTML/JavaScript gets formatted nicely
Also, make sure you are using the necessary escape tags on quotations when needed and that closing braces/semicolons are placed properly before running reformat.
Your JavaScript object's "template" uses a ' (single quote) to open what looks like a multi-line string. There appears to be another single quote on line 49 that may be messing up the inspector.
In the situation that your HTML is in a JavaScript string, it will (correctly) not be formatted. I would remend doing the following:
- Copy the HTML into a separate .HTML file
- Reformat the HTML in there
- Copy the reformatted HTML
- Go back to your object's string value (template)
- write: template: ' ' <-- place your insertion point in between the quotations
- Paste. PHPStorm should automatically escape the quotations for you
本文标签: How to reformat HTML code in JavaScript file in PhpStormStack Overflow
版权声明:本文标题:How to reformat HTML code in JavaScript file in PhpStorm - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744057406a2526099.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论