bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.57k stars 93 forks source link

Intelephense formatter adding extra lines in PHP/HTML between html head and body tags #2838

Closed toggenation closed 2 months ago

toggenation commented 3 months ago

Describe the bug Intelephense formatter adding extra lines in PHP/HTML between html head and body tags

To Reproduce Format the following php document with intelephense

// templates/layout/email/html/gmail_api.php
<?php
/**
 * CakePHP(tm)... license snipped
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
    <title>
        <?= $this->fetch('title') ?>
    </title>
</head>
<body>
    <?= $this->fetch('content') ?>
</body>
</html>

Result

<?php

/**
 * CakePHP(tm)... license snipped
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>

<head>
    <title>
        <?= $this->fetch('title') ?>
    </title>
</head>

<body>
    <?= $this->fetch('content') ?>
</body>

</html>

Expected behavior I would like to be able to turn off the extra lines between the html, head and body tags so the output is:

<?php

/**
 * CakePHP(tm) : ... snipped
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
    <title>
        <?= $this->fetch('title') ?>
    </title>
</head>
<body>
    <?= $this->fetch('content') ?>
</body>
</html>

Platform and version Ubuntu 22.04.3 LTS running in WSL on Windows 11 Pro and licensed Intelephense version v1.10.4

toggenation commented 2 months ago

OK finally found my own answer to this.

Intelephense uses https://github.com/beautifier/js-beautify (which includes HTML formatting).

To stop the extra lines put a .jsbeautifyrc file in the root of your project with the following and it will stop inserting extra lines around head, body & html

{
    "html": {
        "extra_liners": []
    }
}