Reformat code using Prettier in PHP
Prettier is an opinionated code formatter based on NodeJS that supports a variety of languages. Now you can use the power of Prettier with your PHP projects too!
\MallardDuck\PrettierPhp\PrettierHtml::format( html: '<html><body><div><h1>Heading</h1></div></body></html>' );
You can install the package via composer:
composer require mallardduck/prettier-php-runner
prettier installed. You can install it via npm...
npm install prettier
... or Yarn.
yarn add prettier
Make sure you have installed Node 10 or higher.
Here's an example where we are going to highlight some PHP code.
use Spatie\ShikiPhp\Prettier; PrettierHtml::format( '<html><body><div><h1>Heading</h1></div></body></html>' );
The output is this chunk of HTML which will render beautifully in the browser:
<html> <body> <div><h1>Heading</h1></div> </body> </html>
Under the hood, this package will run a node command beautify your HTML input.
If you use NVM during development, then the package will be unlikely to find your version of node as it
looks for the node executable in
If this is the case for you, then you should create a symlink between the node distributable in your NVM folder.
Such a command might look like this:
sudo ln -s /home/some-user/.nvm/versions/node/v17.3.1/bin/node /usr/local/bin/node
Creating this symlink will allow the package to find your NPM executable. Please note, if you change your NPM version you will have to update your symlinks accordingly.
You can run all the tests with this command:
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.