Sublime Forum

Build 3114: PHP and Javascript Syntax Highlighting problem!

#1

Hi,

JavaScript coding in PHP when malfunctioning coloring.

3 Likes

#2

Out of interest, what real world use case is there for conditionally modifying client side code from the server?

0 Likes

#3

You could need to send diferent client side code on behalf user selections, like a selection of client libraries to include

0 Likes

#4

Client libraries could be handled outside of the script block itself though, no?

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <?php
    $a = true;
    if ($a) {
        ?>
        <script src="lib/library1.js"></script>
        <?
    }
    ?>
</head>
<body>

</body>
</html>
0 Likes

#5

Real world use case:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript">
    	$(function(){
    		<?php
    		$loop = ['input_class_1' => 'input_val_1', 'input_class_2' => 'input_val_2']; //Data usually pulled from DB
    		foreach($loop as $k => $v){
    		?>
    		$('.<?php echo $k; ?>').val("<?php echo $v; ?>");
    		<?php
    		}
    		?>
    	});
    </script>
</head>
<body>

</body>
</html>

Arguably you could json_decode your php and then loop through a JS variable instead with a for x in y loop (which I normally do), but then not every coder codes that way.

1 Like

#6

However, the questrion is why sublime 3114 don´t do JS syntax highlighting inside PHP control structures. I´m having that problem too, someone can help?.

P.D.: When I close the php marker, it seems to return to the embedding.php text.html.basic scope

1 Like

#7

Thanks for the example :slightly_smiling:

I’ve been working on an improved syntax definition for classic ASP, and encountered all the same problems that were recently introduced to the PHP syntax. I found a workaround for most of them, and was considering making those same changes for PHP and submitting a pull request. However, handling this one scenario properly just seems too difficult within the current limitations of syntax definitions, hence my interest in whether it has any real use cases.

1 Like

#8

Mind sharing your improved syntax definition for Classic ASP?

0 Likes

#9
0 Likes

#10

Interestingly it’s also affecting HTML tags:

It seems to be whenever you’re in a foreach/if loop and have to break out into HTML/JS then open up a new PHP tag.

0 Likes

#11

That is exactly one of the problems I had to find a workaround for in my ASP syntax definition :wink:

0 Likes

#12

Not to just say me too, but “me too.” I’m having this issue since updating to 3114 as well. I’d be interested in any fixes someone could suggest. What bugs me the most is the HTML tag issue that was just posted.

0 Likes

#13

+1. Problems in PHP, Javascript, HTML highlights

0 Likes

#14

Maybe someone would like to test/try my tweaks here: https://github.com/forkeith/Packages/tree/0ed19d94797fb9397981c66a8b49cf54c3c3d762 - I believe it fixes all problems mentioned in this thread, but there are bound to be other use cases and nuances that it doesn’t cover.

If/when I am able to get it to a state where people like it, I will create a PR :slight_smile:

1 Like

#15

Same problem since updating to 3114, github or keith packages don’t fix the problem, in a file with mixed php and javascript syntax only one of them is highlighted properly; there are no problems with an older version of sublime.

0 Likes

#16

this has been fixed in dev build 3116 (though 3119 is out now). I suggest trying those :slight_smile:

0 Likes

#17

Ok thanks, but I prefer to use the stable versions, any idea when this fixes will be published?

0 Likes

#18

Nope, no idea

0 Likes