![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@shufo/prettier-plugin-blade
Advanced tools
- Automatically indent markup inside directives - Automatically add spacing to blade template markers - PHP 8 syntax support (null safe operator, named arguments) - Compliant to PSR-2 coding standard (PHP code inside directives) - Automatically
Format your blade template using Prettier
tailwind.config.js
$ npm install --save-dev @shufo/prettier-plugin-blade prettier
# yarn
$ yarn add -D @shufo/prettier-plugin-blade prettier
# pnpm
$ pnpm add -D @shufo/prettier-plugin-blade prettier
then, add in your Prettier configuration:
{
"plugins": [
"@shufo/prettier-plugin-blade"
],
"overrides": [
{
"files": ["*.blade.php"],
"options": {
"parser": "blade",
"tabWidth": 4
}
}
]
}
Prettier | Package |
---|---|
3.x | 1.9.x |
2.x | 1.8.x |
$ ./node_modules/.bin/prettier --write resources/**/*.blade.php
https://user-images.githubusercontent.com/1641039/151354641-6305805e-8e0c-4226-8331-64195f85160e.mp4
@extends('frontend.layouts.app')
@section('head')
@endsection
@section('title') foo
@endsection
@section('content')
<section id="content">
<div class="container mod-users-pd-h">
<div class="pf-user-header">
<div></div>
<p>@lang('users.index')</p>
</div>
<div class="pf-users-branch">
<ul class="pf-users-branch__list">
@foreach($tree as $users)
<li>
<img src="{{ asset("img/frontend/icon/branch-arrow.svg") }}" alt="branch_arrow">
{{ link_to_route('frontend.users.user.show',$users["name"],$users['_id']) }}
</li>
@endforeach
</ul>
<div class="pf-users-branch__btn">
@can('create', App\Models\User::class)
{!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!}
@endcan
</div>
</div>
</div>
</section>
@endsection
@section('footer')
@stop
@extends('frontend.layouts.app')
@section('title') foo
@endsection
@section('content')
<section id="content">
<div class="container mod-users-pd-h">
<div class="pf-user-header">
<div></div>
<p>@lang('users.index')</p>
</div>
<div class="pf-users-branch">
<ul class="pf-users-branch__list">
@foreach ($users as $user)
<li>
<img src="{{ asset('img/frontend/icon/branch-arrow.svg') }}" alt="branch_arrow">
{{ link_to_route('frontend.users.user.show', $users['name'], $users['_id']) }}
</li>
@endforeach
</ul>
<div class="pf-users-branch__btn">
@can('create', App\Models\User::class)
{!! link_to_route('frontend.users.user.create', __('users.create'), [1, 2, 3], ['class' => 'btn']) !!}
@endcan
</div>
</div>
</div>
</section>
@endsection
@section('footer')
@stop
You can use these options for prettier blade plugin in prettier CLI.
key | description |
---|---|
--tab-width | Number of spaces per indentation level. default: 4 |
--print-width | The line length where Prettier will try wrap. default: 120 |
--wrap-attributes | The way to wrap attributes. [auto |force |force-aligned |force-expand-multiline |aligned-multiple |preserve |preserve-aligned ]. default: auto |
--end-with-new-line | End output with newline. default: true |
--sort-tailwindcss-classes | Sort Tailwind CSS classes. It will automatically look for and respect tailwind.config.js if it exists. default: false |
--tailwindcss-config-path | Path to your custom Tailwind configuration file. This option is only available if --sort-tailwindcss-classes is present. default: '' |
--sort-html-attributes | Sort HTML Attributes in the specified order. [none | alphabetical | code-guide | idiomatic | vuejs ] default: none |
--no-php-syntax-check | Disable PHP syntax checking. default: false |
.prettierrc
example{
"printWidth": 120,
"tabWidth": 4,
"wrapAttributes": "auto",
"sortTailwindcssClasses": true,
"sortHtmlAttributes": "none",
"noPhpSyntaxCheck": false
}
To disable formatting in your file, you can use blade/html comments in the following format:
{{-- prettier-ignore-start --}}
{{ $foo }}
{{ $bar }}
{{-- prettier-ignore-end --}}
or
<!-- prettier-ignore-start -->
{{ $foo }}
{{ $bar }}
<!-- prettier-ignore-end -->
To disable formatting on a specific line, you can use comment in the following format:
{{-- prettier-ignore --}}
{{ $foo }}
or
<!-- prettier-ignore -->
{{ $foo }}
The editors below are confirmed to work with this plugin.
You can use Prettier extension for VSCode to format blade in VSCode. You need to install this plugin as a local dependency. see https://github.com/prettier/prettier-vscode#prettier-resolution
If you want to use a formatter without Prettier, please consider to use the vscode-blade-formatter instead.
You can use coc-prettier plugin on coc.nvim
If you want to use formater without Prettier, please consider to using coc-blade
You can use the Prettier Plugin for JetBrains IDE.
Add extension setting blade.php
to File | Settings | Languages & Frameworks | JavaScript | Prettier | Run for files
:
e.g.
{**/*,*}.{js,ts,jsx,tsx,blade.php}
and turn on checkbox On 'Reformat Code' action
Restart your IDE if you get the error: 'Prettier: File *.php has unsupported type'
This plugin is based on blade-formatter which does not generate ASTs with lexer, so it might break indentation on complex blade.
Like:
❌ Example of unexpected code
@if ($user)
<div>
@else
</div>
@endif
⭕ Example of expected code
@if ($user)
<div>foo</div>
@else
<div>bar</div>
@endif
Please keep the blade template as simple as possible for better formatting.
You can format the blade file programmatically using Prettier's API
// CommonJS
const prettier = require('prettier');
const input = `
<div>
@if ($user)
{{ $foo }}
@else
{{ $bar }}
@endif
</div>
`;
const res = await prettier.format(input, { parser: 'blade' });
console.log(res);
// =>
//<div>
// @if ($user)
// {{ $foo }}
// @else
// {{ $bar }}
// @endif
//</div>
// ES Module
import * as prettier from 'prettier';
const input = `
<div>
@if ($user)
{{ $foo }}
@else
{{ $bar }}
@endif
</div>
`;
const res = await prettier.format(input, { parser: 'blade' });
console.log(res);
$ yarn install
$ yarn run watch # watch changes
$ yarn install
$ yarn run test
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)
Shuhei Hayashibara |
Beej |
Ian Jamieson |
Morten Scheel |
Nessim Abadi |
Walter Purcaro |
MIT
FAQs
- Automatically indent markup inside directives - Automatically add spacing to blade template markers - PHP 8 syntax support (null safe operator, named arguments) - Compliant to PSR-2 coding standard (PHP code inside directives) - Automatically sort Tailw
The npm package @shufo/prettier-plugin-blade receives a total of 12,227 weekly downloads. As such, @shufo/prettier-plugin-blade popularity was classified as popular.
We found that @shufo/prettier-plugin-blade demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.