Vim php_javascriptInStrings option?

I noticed that the /php.vim syntax file on my ubuntu machine has the php_htmlInStrings parameter. I can enable this option to display HTML syntax highlighting in lines in my php files, which is great. I would also like to make javascript syntax highlighting in lines in php file. Does anyone know if this can be done, and if so, how can I do this?

edited - added additional features

I should also mention that I would be happy with a solution in which I would need to parse all my javascript strings, despite the php function, before outputting the result. This can get around the problem suggested by conner below, where vim has problems deciding whether the javascript string contains. eg:

 $js = "some regular text which is not javascript##now vim has detected that this part is javscript##back to regular text"; parse($js); function parse($str) { return str_replace('##', '', $str); } 

The reason I would be happy to do this is because I will probably include in my project the html / css / js minifier variable, which will do replacements on strings anyway.

Of course, if for ## there is an equivalent vim character that will not be displayed in the source code and will not need to be filtered out, this would be preferable ...

redo 2

In accordance with the solution below, the desired effect can be achieved as follows:

 $js = "<script>some javascript</script>"; 

(with :let php_htmlInStrings=1 in vim). If someone can show me that a vim script is required so that the javascript syntax highlighting appears in the next line, I will give them the answer:

 $js = /*<script>*/"some javascript"/*</script>*/; 
+6
source share
2 answers

I think the general problem is that vim needs a way to differentiate javascript and HTML highlighting. In HTML files, vim determines this based on the <script></script> inside it to apply javascript highlighting. If you put the <script></script> in your line, you will see that it is. However, if you remove them, then vim will not be able to find out if the content in your string is HTML or javascript. You can fix this by editing the addition of something to indicate that it is javascript, which I hope will not affect the resulting code, but it is difficult. You can see where the HTML file sets the specification of the <script></script> on line 167 $VIMRUNTIME/syntax/html.vim . It looks like this:

 syn region javaScript start=+<script[^>]*>+ keepend end=+</script>+me=s-1 contains=@htmlJavaScript ,htmlCssStyleComment,htmlScriptTag,@htmlPreproc 
+2
source

Have you tried this php.vim file?

0
source

Source: https://habr.com/ru/post/921359/


All Articles