Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force closing HTML tags on a new line?

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.

like image 804
LeKevoid Avatar asked Aug 27 '18 14:08

LeKevoid


People also ask

How do I close HTML tags?

An opening tag begins a section of page content, and a closing tag ends it. For example, to markup a section of text as a paragraph, you would open the paragraph with an opening paragraph tag <p> and close it with a closing paragraph tag </p> (closing tags always proceed the element with a /).

How do I close a self closing tag?

A self-closing tag is an element of HTML code that has evolved in the language. Typically, the self-closing tag makes use of a “/” character in order to effectively close out a beginning tag enclosed in sideways carets.

Does HTML have self closing tags?

Self Closing HTML ElementsThe br tag inserts a line break (not a paragraph break). This tag has no content, so it is self closing.


1 Answers

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.

like image 173
BitwiseMan Avatar answered Oct 11 '22 22:10

BitwiseMan