prettier / plugin-php

Prettier PHP Plugin
https://loilo.github.io/prettier-php-playground/
MIT License
1.75k stars 129 forks source link

Laravel blade support #1120

Open vielhuber opened 5 years ago

vielhuber commented 5 years ago

Hello!

The blade templating engine in laravel is not supported at the moment (it seems).

Are there any plans to add this in the future?

Is this hard to do and can I help out?

alexander-akait commented 5 years ago

We need parser for this

vielhuber commented 5 years ago

Can you provide some starter instructions how to contribute and where to start?

czosel commented 5 years ago

Hi @vielhuber, I think this would require a separate prettier plugin which consists out of a blade parser and custom formatting rules for blade templates. This probably requires a lot of work, see https://prettier.io/docs/en/plugins.html for more details.

alexander-akait commented 5 years ago

@vielhuber Can blade using not only in php?

vielhuber commented 5 years ago

The blade templates always have the .php extension (filename is always *.blade.php).

alexander-akait commented 5 years ago

@czosel i think we should do this inside this plugin

shufo commented 5 years ago

I have recently created a formatter for blade. Using prettier and plugin-php inside it. https://github.com/shufo/blade-formatter It's not based on blade dedicated lexer or parser so supported syntax is limited. I hope plugin-php supports blade officially.

jpickwell commented 4 years ago

@vielhuber, GitHub's Linguist has .blade and .blade.php as the extensions for blade templates. I understand that .blade is not standard, but it's trivial to support that extension in addition to the official .blade.php scoped extension.

@shufo, it's cool that you've started work on something. However, it would be nice if your project were either a prettier plugin, or merged into this plugin. I don't like the idea of having to use another CLI tool just for blade templates when I'm already using Prettier with this plugin.

vielhuber commented 4 years ago

@shufo: Is there any way to run both blade-formatter and plugin-php at the same time?

For me it seems that plugin-php also formats blade.php files and gets in conflict with blade-formatter (which runs with RunOnSave).

Do you consider making a vscode prettier plugin for that?

surgiie commented 4 years ago

FWIW, using the html parser formats pretty well imo, it does kind of fail at formatting the @ directives and blade brackets {{ }}, but im okay with manually fixing those after running the formatting on a blade file.

vielhuber commented 3 years ago

Does anybody know: Is there any way to run both blade-formatter and plugin-php at the same time?

I both use the plugins and they seem to work quite good, however when I am formatting a *.blade.php file, the php-prettier parser interfers. it should ignore that types of files and let blade-formatter do it's job.

czosel commented 3 years ago

Did you already try adding *.blade.php to .prettierignore?

vielhuber commented 3 years ago

Jup, that works! Thanks in advance!

rinaldycodes commented 3 years ago

*.blade.php

how to add *blade.php to .prettierignore

davidwebca commented 2 years ago

Is there anyone working on this currently? Otherwise, could someone point me to the HTML parser code so I can take a look at it? HTML parser does 99% of the job except ignores "@" rules, so it seems like the closest place to start. I could potentially help on that.

czosel commented 2 years ago

Hi @davidwebca, I donโ€™t think anyone is currently working on this. The HTML parser is not part of this repository, but of the main prettier project: https://github.com/prettier/prettier/tree/main/src/language-html

iAmKevinMcKee commented 2 years ago

Would be great to see this start working. I think a lot of us Laravel users (myself included) are excited to use the new Tailwind plugin, but we can't use it on any of our blade files.

I wish I could be more helpful in making this happen. Thank you to anyone who has the time and ability to get blade files working.

admench commented 2 years ago

https://twitter.com/taylorotwell/status/1486085543960186882

Don't know what is involved to get this to work but Taylor said this โ˜๐Ÿผ

retlehs commented 2 years ago

we'll (@roots) also contribute $500 on top of the $1,000 put up by taylor

https://twitter.com/rootswp/status/1486088875034484739

besfortoruci commented 2 years ago

Update: It's $3,500 ๐Ÿ˜Ž

https://twitter.com/taylorotwell/status/1486095091743830021

ConsoleTVs commented 2 years ago

There seems to be a work in progress here: https://github.com/ryangjchandler/prettier-plugin-blade

davidwebca commented 2 years ago

Nice! Glad to hear Tailwind releasing Prettier support kicked the thing, I've been watching this issue for so long I was just about to scratch the issue myself. I'm not after the bounty, I'll leave that to Ryan, but I'll lend a hand by looking through the code and testing it. ๐Ÿ”ฅ

shufo commented 2 years ago

I noticed this issue is recently active again so I released prettier plugin for blade

https://github.com/shufo/prettier-plugin-blade

It's not lexer based plugin generating ASTs, so there is a bit of limitation, but it generally works fine for normal blade templates.

https://user-images.githubusercontent.com/1641039/151354641-6305805e-8e0c-4226-8331-64195f85160e.mp4

Ryan's work would be great if it could be done! I'm looking forward to it.

@jpickwell sorry for late!

alexander-akait commented 2 years ago

@czosel @olivernybroe What do you think embed it here? I think it will be convenient for developers

ryangjchandler commented 2 years ago

@olivernybroe and I are hoping we can cover a lot of the edge cases that other formatters for Blade don't cover yet. We'll be using a lexer & parser to tackle this.

czosel commented 2 years ago

@alexander-akait Yeah, it probably fits to the scope of the PHP plugin. Back when this was brought up for the first time I was hesitant, but mostly because of the complexity involved. From the user's perspective, it would be nice to get PHP and blade support out of the same plugin I'd say :+1: