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

Follow indent rule of PHP ruleset #32

Closed nbordeau closed 4 years ago

nbordeau commented 5 years ago

I work on multiple PHP projects with different rulesets (PSR2, WordPress-Extra, etc...) and the default "Detect Indentation" in VS Code normally is not able to detect it properly. Therefore sometimes when I have the WordPress-Extra ruleset in my .phpcs.xml file, Format HTML in PHP starts indenting everything with spaces even though they are supposed to be tabs.

Before Example:

<!doctype html>
<html <?php language_attributes(); ?>>
    <head>
        <meta charset="<?php bloginfo( 'charset' ); ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="profile" href="https://gmpg.org/xfn/11">
        <link rel=icon href="<?php echo esc_url( '/wp-content/uploads/theme-images/favicon.png' ); ?>" type=image/png>
        <?php wp_head(); ?>
    </head>
    <body <?php body_class(); ?>>
        <div id="page" class="site">

After Format HTML in PHP:

<!doctype html>
<html <?php language_attributes(); ?>>

    <head>
        <meta charset="<?php bloginfo( 'charset' ); ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="profile" href="https://gmpg.org/xfn/11">
        <link rel=icon href="<?php echo esc_url( '/wp-content/uploads/theme-images/favicon.png' ); ?>" type=image/png>
            <?php wp_head(); ?> </head> <body <?php body_class(); ?>>
        <div id="page" class="site">

I would expect the HTML formatting to abide by similar rules as the PHP formatting. If spaces are used via PHP, then spaces should be used in HTML. If tabs, then tab in both.

RiFi2k commented 4 years ago

@nbordeau What is your setting for editor.insertSpaces? That is what it goes off to format.

RiFi2k commented 4 years ago

Oh and I was going crazy about the formatting and I finally figured out what was causing it to get all messed up.

type=image/png>

Missing the quotes on the type attribute here tricks it into thinking its closing one of the tags

type="image/png">

I know you technically aren't required to use quotes here because its only if it contains " ' ` = < > but it will fix your issue.

RiFi2k commented 4 years ago

Closing this unless someone wants me to keep it open then go ahead and comment.