简体   繁体   English

如何强制关闭新行上的HTML标记?

[英]How to force closing HTML tags on a new line?

In VS Code, I use Beautify extensively. 在VS Code中,我广泛使用Beautify。 But it unnerves me that closing tags always wrap on the same line as "floating" text, or self-closing tags. 但令我感到不安的是,结束标签总是与“浮动”文本或自闭标签包装在同一行。 For instance, before Beautify : 例如,在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 : 在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. 在大多数情况下这并不重要,除了对我的品味有点难看,但昨天我看到它实际上产生了Wordpress的问题,我不能再使用Beautify了,它有可能打破格式化。

There isn't an option to force the end tags to new lines. 没有选项强制结束标记到新行。

One setting that helps is preserve_newlines . 一个有用的设置是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. js-beautify的版本1.8.1(用于VSCode的Beautify库)改进了该区域的行为,但仍然没有强制结束标记到新行的选项。

Several issues have been filed around this, including #1468 and #1413 . 围绕此提出了几个问题,包括#1468#1413 PRs are always welcome. PR总是受欢迎的。

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.Com,由制作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 Glitch托管你的网站(website.glitch.com),并有一个很好的编辑器,如果你想恢复到以前的版本,更不用说项目倒带..你也有光明和黑暗的主题..它会自动关闭像这样的标签

<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 自动保存并适合任何开发人员:3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM