RiFi2k / format-html-in-php

Basically this vscode extension uses all your standard configurations for html formatting, and your standard configurations for format on save, etc. It more or less works exactly how vscode should already work as it pertains to HTML in PHP files.
The Unlicense
33 stars 6 forks source link

If/else indent #33

Closed Shou-nen closed 4 years ago

Shou-nen commented 5 years ago

Before:

<?php if (1) : ?>
<p class="c1">
<?php else : ?>
<p class="c2">
<?php endif ?>
text
</p>

After:

<?php if (1) : ?>
<p class="c1">
    <?php else : ?>
    <p class="c2">
        <?php endif ?>
        text
    </p>

It doesn't look good.

ovidiu-balau commented 4 years ago

Any news on fixing this?

RiFi2k commented 4 years ago

@ovidiu-balau So realistically you would use an inline ternary operator in that particular example. The reason the formatting is messed up is because the

tags aren't being open and closed properly.

This would be a more realistic example of doing that in the real world.

<p class="<?php echo (1) ? 'c1' : 'c2'; ?>">
text
</p>

After

<p class="<?php echo (1) ? 'c1' : 'c2'; ?>">
  text
</p>

Which is pretty much as expected. So a more realistic look at the else endif situation would be doing something like this.

<p>
<?php if (1) : ?>
<span class="c1">
hi
</span>
<?php else : ?>
<span class="c2">
hi
</span>
<?php endif ?>
text
</p>

After

<p>
  <?php if (1) : ?>
  <span class="c1">
    hi
  </span>
  <?php else : ?>
  <span class="c2">
    hi
  </span>
  <?php endif ?>
  text
</p>

Which also comes out as expected.

Feel free to reopen this if you think I'm missing something here, I would be happy to take another look at a different example.