Problem with syntax highlighting/code folding for files that include a javascript template

I have a file containing javascript code but it is a template, so other than the typical javascript syntax, it contains also template tags like <% or %> .

Actually the file has an ejs extension, but ejs is made for html code, so the syntax highlighting for it doesn't work very well (it doesn't recognize a file that starts directly with javascript not embedded in <script> tag).

So I changed the settings such that Webstorm considers the file as a javascript file.

In this way the syntax hightlighting is correct.

But still, in this way it doesn't offer code collapse/folding feature.

How can i have both correct syntax highlighting and code collapsingfolding feature?

Which template engine should I use? I tried with mustache/handlebar, but in this case webstorm does not recognize some symbols, like greater than symbol '>' and others.

6 comments

Please can you attach a .ejs file you have the problems with?

0

https://s3-eu-west-1.amazonaws.com/bitliner.images/Screenshot+from+2014-05-07+23%3A42%3A14.png
This is an example.

As you can see, I cannot fold a function like MessageReceiver at line 14.

0

Elena asked for actual file (simplified version .. or even made up one -- it just need to illustrate the problem) and NOT a screenshot of it.

P.S.

So I changed the settings such that Webstorm considers the file as a javascript file.

How did you do that -- via Template Data Languages?

0

You can easily create a file, just create an ejs file e put some lines of javascript that uses the ejs tempalte language.

Like index.ejs with the content:

var a='<%= variable %>';

var f=function(a,b){

     console.log(a+b,a,b);

}

I changed the settings to read that file, basically what I did is:

  • naming the file with the extensions .js.ejs, like filename.js.ejs
  • in setttings -> File Types I added a new file type, called templte in js, and I configured it such that the Line comment is //, block comment start is /* and block comment end is */ and adding as keywords <%

This was the only way to not display syntax errors that were'nt syntax errors.
Byt still, I cannot fold/expand code functions.

Which may be a template engine for javascript that works well also with Webstorm?

0
in setttings -> File Types I added a new file type, called templte in js, and I configured it such that the Line comment is //, block comment start is /* and block comment end is */ and adding as keywords <%

That's the problem.

You have created new CUSTOM file type. But IDE does not offer code folding for custom file types -- it's only available in supported (via plugins) file types.

Instead:

  • Settings | Template Data Languages
  • Locate your file(s) or whole folder(s) and assign desire language (JavaScript in your case) instead of default (which is HTML, in our case).



This is how it looks for me (file name: "ejs.ejs"):
screen01.png
As you can see code folding is there.

0

Thank you very much. It works.
Loving you :-)

0

Please sign in to leave a comment.