atom / language-php

PHP package for Atom
Other
119 stars 118 forks source link

PHP syntax not recognized inside HTML quotes #409

Open wasinwill opened 3 years ago

wasinwill commented 3 years ago

If an HTML code similar to style="background-image:url(<?= $image_url ?>)" is added to a .php file, Atom fails to recognize PHP tags if any character is entered after url(. See picture below:

Screenshot 2021-01-03 213839

After inspecting the elements with Developer Tools, it looks like it isn't theme-related. The example below shows when it works, with a code like url(<?= $image_url ?>). The tag is recognized and encapsulted inside a syntax--php element.

Screenshot 2021-01-03 214257

However, when a character is added after the bracket, such as url(/img/<?= $image_url ?>.jpg), the tag is no longer recognized and sits inside a syntax-css element.

Screenshot 2021-01-03 214359


Version 1.53.0 x64 Electron 6.1.12 Chrome 76.0.3809.146 Node v12.4.0 Theme One Dark

KapitanOczywisty commented 3 years ago

I'm afraid this is won't fix issue. Syntax injections are broken by definition, since you can insert any piece of code in any place. In this situation there is no good way to fix php injection in another syntax block.

As I always say in these issues: try to avoid injections all together, there are better ways to pass data between languages.

wasinwill commented 3 years ago

VS Code handles it perfectly though (see screenshot below).

Plus, PHP and HTML are meant to co-exist by design, and I think that syntax is a lot better than something like <?php echo "<div class='img' style='background-image:url(/img/$image_id.jpg'></div>"; ?> as you keep HTML in HTML and PHP in PHP, especially for something this basic.

But however you'd prefer to write this, Atom isn't behaving as expected, and VS Code is, so I'm not sure why fixing this would be off-limits, while the people working on VS Code have clearly figured it out.

Screenshot 2021-01-04 074422

Ingramz commented 3 years ago

I wouldn't call it a wontfix before at least exploring why the injection doesn't work between text.

VSC doesn't parse CSS inside style attribute. This example is more suitable:

<style>
div {
  background-image: url(a<?= $image_url; ?>);
}
</style>

which based on my testing exhibits the same behavior where it isn't working mid-text.

KapitanOczywisty commented 3 years ago

image

@wasinwill You were saying? VSCode and atom are using different syntax for css and html.

I'm not sure what is go-to nowadays for php/html templating, but I'm sure there are better ways which have full IDE support. Even going with attribute and propagating this with JS might be better.

@Ingramz We have so many problems like that with SQL and HTML that I'm rather confident this will be at least time consuming to mitigate. And I've checked what tokens are involved in this.

wasinwill commented 3 years ago

@KapitanOczywisty I'm confused. Your screenshot shows that it doesn't work inside