On Thu, Aug 2, 2012 at 1:20 AM, Ben Fritz <[email protected]> wrote:

> On Wednesday, August 1, 2012 1:08:35 AM UTC-5, mulllhausen wrote:
> > hi all,
> >
> > i gather from the lack of response that my previous question has no
> feasible answer. anyway, i have updated the question a bit to give some
> other possible ways of solving the problem. any pointers in the right
> direction would be much appreciated. i am pretty competent with vim but i
> have little to no vim scripting. then again i am a quick learner and very
> eager haha...
> >
> >
> > here is the updated question:
> http://stackoverflow.com/questions/11661614/vim-php-javascriptinstrings-option
> >
> >
> >
> >
> >
> >
> >
> > I noticed that the syntax/php.vim file on my ubuntu machine has a
> php_htmlInStrings
> >  option. I can turn this option on to display HTML syntax highlighting
> > within strings in my php files, which is great. I would also like to do
> > javascript syntax highlighting within strings in a php file. Does
> > anybody know if this can be done and if so how can I do it?
> >
> >
> > edited - added extra possibilities
> >
> >
> > I should also mention that I would be happy with a solution where i
> > have to parse all my javascript strings though a php function before
> > outputting the result. This might get around the problem suggested by
> > connor below where vim has trouble deciding if the string contains
> > javascript. for example:
> >
> > $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 be
> > incorporating a html/css/js variable minifier into my project which will
> >  be doing substitutions on strings anyway.
> >
> >
> > Of course if there is a vim-specific equivalent character for ## which
> will not show up in the source code and would not need to be filtered out
> then this would be preferable...
>
> I personally passed up the question because I don't know of a way that is
> already built into the php syntax script but maybe one exists.
>
> It's possible to do, see
> http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_fileand
>  the help links it gives but it will require a lot of work on your part
> to do it yourself.
>
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>


thanks for the replies people! and no worries if it takes a while :)

somebody on stackoverflow showed me that if i put <script> at the start of
the string, then turn on the html syntax highlighting, vim will interpret
the string as javascript and format accordingly.

my line 167 in syntax/html.vim previously looked like this:

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

so i commented it out and changed "script" to "js". i have a work around
now where i parse all javascript strings through a function to strip out
the opening tag (i found that i dont actually need a closing tag for vim to
give the proper syntax highlighting). however, while this is functional, it
would be nice if i could use the following format to get the syntax
highlighting:

/*<js>*/ "this string should have javascript syntax highlighting" /*</js>*/

i have had a go at this but i'm a bit new to the way that vim groups
regions under headings so i didn't get it right. line 340 in syntax/php.vim
currently reads:

  syn region  phpComment  start="/\*" end="\*/" contained contains=phpTodo

so i tried changing it to:

  syn region  phpComment  start="/\*" end="\*/" contained
contains=@htmlJavascript,phpTodo

but that doesn't do it.

actually if somebody could give me some pointers as to a good place to
learn about the vim syntax regions that would be a great help. or if
anybody can tell me how i could alter my syntax/ files that would be even
better!

thanks in advance!
peter

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to