Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettier - allow line breaks between html elements

I'd like to keep some space between some html blocks in my code. However, Prettier wants to remove these lines. Is there a Prettier setting to keep this spacing?

Before prettier:

<template>
  <form>

    <div>First block</div>

    <div>Second block</div>
    
  </form>
</template>

After pretter:

<template>
  <form>
    <div>First block</div>

    <div>Second block</div>
  </form>
</template>
like image 792
Mads Hjorth Avatar asked Jan 19 '26 07:01

Mads Hjorth


1 Answers

There is no way to actually do this, you might only use tricks.

First trick

Ignore completely the file (or file extensions) but you will not benefit from Prettier

Second trick

Deny Prettier to trim whitespaces

trim_trailing_whitespace = true

And add whitespaces in line breaks. Once again this is not an effective solution, it's only a trick.

An issue has been closed by devs

adding and removing line breaks is core to prettier's formatting algorithm

like image 118
IQbrod Avatar answered Jan 20 '26 21:01

IQbrod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!