Skip to content

How to format HTML in PHP templates #845

@claytonrcarter

Description

@claytonrcarter

Prettier 1.15.2
PHP Plugin 0.9.0

Now that prettier supports formatting HTML, how can we have plugin-php format PHP and HTML in a PHP file?

Input:

<?php
$somePoorly    = 'formatted'. 'code' .
'right'       .
 ( isset( $nope) ? 'here'
:
'and here'
)
;

?>
<html
><head

>

</head>
<body>
More
bad
code here.
</body
>

</html>

Output of prettier test.php: (PHP is properly formatted, HTML is not.)

<?php
$somePoorly =
    'formatted' . 'code' . 'right' . (isset($nope) ? 'here' : 'and here'); ?>
<html
><head

>

</head>
<body>
More
bad
code here.
</body
>

</html>

Output of prettier test.php --parser html: (HTML is properly formatted, PHP is not.)

<?php $somePoorly = 'formatted'. 'code' . 'right' . ( isset( $nope) ? 'here' :
'and here' ) ; ?>
<html>
  <head> </head>
  <body>
    More bad code here.
  </body>
</html>

Expected behavior: (Both PHP & HTML are properly formatted.)

<?php
$somePoorly =
    'formatted' . 'code' . 'right' . (isset($nope) ? 'here' : 'and here'); ?>
<html>
  <head> </head>
  <body>
    More bad code here.
  </body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions