plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Laravel blade support

Open vielhuber opened this issue 5 years ago • 26 comments

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?

vielhuber avatar Aug 24 '19 20:08 vielhuber

We need parser for this

alexander-akait avatar Aug 26 '19 10:08 alexander-akait

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

vielhuber avatar Aug 26 '19 10:08 vielhuber

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.

czosel avatar Aug 26 '19 10:08 czosel

@vielhuber Can blade using not only in php?

alexander-akait avatar Aug 26 '19 10:08 alexander-akait

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

vielhuber avatar Aug 26 '19 10:08 vielhuber

@czosel i think we should do this inside this plugin

alexander-akait avatar Aug 26 '19 10:08 alexander-akait

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.

shufo avatar Oct 28 '19 21:10 shufo

@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.

jpickwell avatar Dec 06 '19 20:12 jpickwell

@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?

vielhuber avatar Dec 07 '19 20:12 vielhuber

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.

surgiie avatar May 06 '20 18:05 surgiie

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.

vielhuber avatar Jan 16 '21 21:01 vielhuber

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

czosel avatar Jan 16 '21 21:01 czosel

Jup, that works! Thanks in advance!

vielhuber avatar Jan 16 '21 21:01 vielhuber

*.blade.php

how to add *blade.php to .prettierignore

rinaldycodes avatar Mar 16 '21 03:03 rinaldycodes

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.

davidwebca avatar Jan 24 '22 22:01 davidwebca

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

czosel avatar Jan 24 '22 23:01 czosel

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.

iAmKevinMcKee avatar Jan 25 '22 19:01 iAmKevinMcKee

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

Don't know what is involved to get this to work but Taylor said this ☝🏼

admench avatar Jan 25 '22 21:01 admench

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

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

retlehs avatar Jan 25 '22 21:01 retlehs

Update: It's $3,500 😎

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

besfortoruci avatar Jan 25 '22 21:01 besfortoruci

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

ConsoleTVs avatar Jan 26 '22 02:01 ConsoleTVs

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. 🔥

davidwebca avatar Jan 26 '22 17:01 davidwebca

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!

shufo avatar Jan 27 '22 12:01 shufo

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

alexander-akait avatar Jan 27 '22 12:01 alexander-akait

@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.

ryangjchandler avatar Jan 27 '22 15:01 ryangjchandler

@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:

czosel avatar Jan 27 '22 19:01 czosel