Medalink / laravel-blade

This package adds syntax definitions for the Laravel Blade engine.
http://www.laravel.com
MIT License
421 stars 103 forks source link

Add Livewire and Laravel 7 component tags support #190

Closed mylesduncanking closed 2 years ago

mylesduncanking commented 3 years ago

Never written syntax code before so this may need to be rewritten in a better way

I was trying to get it so that if you had <livewire:component :param="['foo' => 'bar']" param2="foo-bar" /> the content between the speech marks on :param would be formatted as PHP but couldn't quite figure it out.

The syntax is that a colon parameter is passed as php whereas if no colon is present its passed as a string.

If you are able to add that funcationality by building on what i've added then awesome, if not, its not the end of the world as the red highlighting is now gone which was the main reason I looked into it.

owenandrews commented 3 years ago

Just installed this manually to give it a try and found that unfortunately it seems to incorrectly identify any classes containing x- as a blade component.

image

owenandrews commented 3 years ago

Managed to fix it by changing line 147 blade.sublime-syntax to - match: '(?<=<|</)(x-[a-zA-Z\-._]*\s?)'. The positive lookbehind checks to ensure it is proceeded by a left arrow. Not sure if this has any negative consequences?

Medalink commented 3 years ago

@mylesduncanking as @owenandrews pointed out we need to include the open and closing tags in the match regex. We are greedily matching within the HTML/PHP scope (check here) so the only way to prevent text from being gobbled into it is to strictly match onto it. This also needs to be the very last entry here since the way ST works is the first match with a pop will stop applying that rule to the next. We want to ensure that when a <x- match is found we pop and stop looking again.