Home Download Buy Blog Forum Support

Custom JavaScript Block in HTML and Code Completion

Custom JavaScript Block in HTML and Code Completion

Postby dggtydnk on Fri Dec 27, 2013 6:24 pm

I have a server side processor that interprets all blocks surrounded with %serversidejs% as javascript that is executed on the server before the HTML page is served up. For example:
Code: Select all
<p>some text</p>
%serversidejs%
var temp = ["a", "b", "c"];
for(var i=0; i < temp.length; i++)
    print("<p>" + temp[i] + "</p>");
%serversidejs%
<p>some more text</p>

I was trying to emulate the <script> handler in HTML.tmLanguage to get it to work, but can't seem to get it to work. There are a few regular expressions that have unfamiliar syntax, in particular:
Code: Select all
   <key>end</key>
   <string>(?&lt;=&lt;/(script|SCRIPT))(&gt;)(?:\s*\n)?</string>

   <key>begin</key>
   <string>(?&lt;!&lt;/(?:script|SCRIPT))(&gt;)</string>

I am not familiar with the (?&lt;=&lt and (?&lt;!&lt; syntax in the above. Can anyone tell me what those are doing?

My next attempt was a very, very basic handler:
Code: Select all
   <dict>
      <key>begin</key>
      <string>(?:^\s+)?(%)((?i:serversidejs))\b(?![^%]*/%)</string>
      <key>end</key>
      <string>(%/(serversidejs))(%)(?:\s*\n)?</string>
      <key>name</key>
      <string>source.js.serversidejs.embedded.html</string>
      <key>patterns</key>
      <array>
         <dict>
            <key>include</key>
            <string>source.js</string>
         </dict>
      </array>
   </dict>
   <dict>

This shows javascript syntax highlighting and shows course.js.serversidejs.embedded.html when I hit Ctrl+Alt+Shift+P when inside a %serversidejs% block, however, the SublimeCodeIntel does not seem to pick it up as JavaScript. Any ideas how to get SublimeCodeIntel to recognize this block as JavaScript?
dggtydnk
 
Posts: 1
Joined: Fri Dec 27, 2013 12:29 am

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 37 guests