How to force closing HTML tags on a new line?

ぐ巨炮叔叔 提交于 2019-12-07 01:09:51

问题


In VS Code, I use Beautify extensively. But it unnerves me that closing tags always wrap on the same line as "floating" text, or self-closing tags. For instance, before Beautify :

<div class="wrap">
    <img src="/wp-content/uploads/2018/08/image.png">
</div>
<div class="wrap">This is just some text
    <strong>but it needs to be emphasized</strong>! And then some...
</div>

And after Beautify :

<div class="wrap">
    <img src="/wp-content/uploads/2018/08/image.png"> </div>
<div class="wrap">This is just some text
    <strong>but it needs to be emphasized</strong>! And then some... </div>

Is there a setting, or another extension that could help get the code closer to what it looks like in the first example, or am I just doing things wrong ?

It doesn't matter much most of the time, other than being a bit ugly to my taste, but yesterday I saw that it actually created problems with Wordpress, I just can't use Beautify anymore, it risks breaking the formatting.


回答1:


There isn't an option to force the end tags to new lines.

One setting that helps is preserve_newlines. Enabling that should keep your tags from getting pulled back to the same line if you have them on their own line.

Version 1.8.1 of js-beautify (the library underlying Beautify for VSCode) improves the behavior in this area, but still doesn't have an option to force the end tags to new lines.

Several issues have been filed around this, including #1468 and #1413. PRs are always welcome.




回答2:


I do not know about that. If you want a similar result to the top bit of code you could use Glitch.Com, Made by the people who made stackoverflow. Glitch hosts your website (website.glitch.com) and has a nice editor, Not to mention project rewind if you want to revert to a previous version.. You have light and Dark theme too.. It automatically closes tags like this

<h1>

</h1>

I think it is perfect compared to any other editor, You can have multiple files too.. no download required. Auto saving and perfect for any developer :3



来源:https://stackoverflow.com/questions/52041125/how-to-force-closing-html-tags-on-a-new-line

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