ilex01's avatar

Add a new line before and after the <div> tag in PhpStorm

Hi!

Here is my current HTML code in PhpStorm:

<body>
    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
</body>

When I Reformat Code, I would like this:

<body>
    <!-- Empty line here in PhpStorm -->
    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
    <!-- Empty line here in PhpStorm -->
    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
    <!-- Empty line here in PhpStorm -->
</body>

I've been looking for hours in the HTML Code Style, but can't seem to make it work.

Thank you for your help.

0 likes
11 replies
jlrdw's avatar

Empty line here in PhpStorm

What does PhpStorm have to do with an empty line:

Either

<br>

or

<div class="cf"></div>

where cf is:

.cf { content:".";
    /*display:table;*/
    width:100%;
    display:block;
    clear:both;
    height: 10px;
    font-size:0;
    line-height:0;
    visibility:hidden;
    overflow:hidden; }
.cf:after { clear:both; } .cf { *zoom:1; }
* html .cf { zoom: 1; } /* IE6 */
*:first-child+html .cf { zoom: 1; } /* IE7 */
bugsysha's avatar
Preferences > Editor > Code Style > Other > Insert new line before

But there is no option for after element.

ilex01's avatar

Hey jlrdw,

I thank you very much for your answer! I think it was a little bit confusing but I meant: I want to add a new line before and after the tag in the IDE (when I use the Reformat Code action). I don't want to add a new line in the browser.

ilex01's avatar

Hi bugsysha,

Thank you for your answer!

Yes, I already did that, and it doesn't even add a line before the div tag. (I've added the div tag in the input to the right of the: "add a line before the div tag").

bugsysha's avatar

It is working for me. Are you sure you've used it on HTML and not on some templating engine file?

bugsysha's avatar

I've meant when you try to reformat. On which file did you run that action?

Screenshot looks OK.

ilex01's avatar

Thank you for your help!

On a filed named: test1.html. An .html file.

Thank you for the screenshot.

However, to the right of the screenshot, we can see that there is no new line before the first and the second div?

And I've set the div tag in: Preferences > Editor > Code Style > Other > Insert new line before

bugsysha's avatar

That does not say that it will have additional new line before that tag, but that tag will be on a separate line. So it is working as it is stated.

1 like
ilex01's avatar

I see, thank you!

Then I guess there is no option to add a new line before a div?

bugsysha's avatar
bugsysha
Best Answer
Level 61

Additional NO, to be on separate YES.

Please or to participate in this conversation.