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

Want a style keep php block #27

Open dvaknheo opened 5 years ago

dvaknheo commented 5 years ago

at first thank you to this good extension.

my code e.g.:

<ul>
<?php 
foreach($data as $v){
?>
    <li><?=$v?></li>
<?php
} 
?>
</ul>

do keep it. don't want to be this as default :

<ul>
    <?php 
foreach($data as $v){
?>
    <li>
        <?=$v?>
    </li>
    <?php
} 
?>
</ul>

because my style of php indent follow by <?php . not with the html. each time "<?php" is in first ,no has space before. so you can watch the php code clearly. and that cause no the space-fill line change the output.

<?= is as a word mixed in html .

RiFi2k commented 5 years ago

So your looking to have the initial PHP tag not move itself out to the current indentation on the first HTML tag?

You can demo how the library works here as well - https://beautifier.io/

Personally I would write it like this

<ul>
    <?php foreach($data as $v){ ?>
    <li><?=$v?></li>
    <?php } ?>
</ul>
BartolomeSintes commented 4 years ago

Hi, I would add another example of this problem. This is a php file:

<ul>
<?php
    print "  <li>This is a list</li>\n";
    print "  <li>with two items</li>\n";
?>
</ul>

This code generates the following html

<ul>
  <li>This is a list</li>
  <li>with two items</li>
</ul>

But if I format the php file using Format HTML in PHP, the program is now:

<ul>
  <?php
    print "  <li>This is a list</li>\n";
    print "  <li>with two items</li>\n";
?>
</ul>

Notice that the <?php has been indented two spaces This code generates the following html

<ul>
    <li>This is a list</li>
  <li>with two items</li>
</ul>

Notice that the first <li> has 4 spaces instead of 2. A configuration option like php-cs-fixer.indentPhpTag: true/false could solve this issue. Thanking you in advance,