Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Javascript highlighting in CDATA content(cannot highlight JavaScript in CDATA in XML file)
Javascript highlighting in CDATA content [message #533797] Mon, 17 May 2010 07:16 Go to next message
xemox  is currently offline xemox
Messages: 9
Registered: May 2010
Junior Member
Hi People, Smile

We have a lot of xml files with embedded JavaScript code in CDATA content of XML documents. Because of CDATA it display the JavaScript without syntax highlighting.

For example:

<page id="admin" title="Administration">
<js:visible>
<![CDATA[
session.currentDatabase.accessLevel > 1 && (session.currentUser.getManagedUnits.length > 0 || session.currentUser.hasId(['{manager}', '[TemplateAdmin]']));
// true
]]>
</js:visible>
<outline>outline.olnAdministration</outline>

</page>



How can we enable Javascript highlighting in CDATA in Eclipse?

Thanks!

[Updated on: Mon, 17 May 2010 07:17]

Report message to a moderator

Re: Javascript highlighting in CDATA content [message #534409 is a reply to message #533797] Wed, 19 May 2010 04:25 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2314
Registered: July 2009
Senior Member
On 5/17/2010 3:16 AM, xemox wrote:
> Hi People, :)
> We have a lot of xml files with embedded JavaScript code in CDATA
> content of XML documents. Because of CDATA it display the JavaScript
> without syntax highlighting.
>
> For example:
>
> <page id="admin" title="Administration">
> <js:visible><![CDATA[
> session.currentDatabase.accessLevel > 1 &&
> (session.currentUser.getManagedUnits.length > 0 ||
> session.currentUser.hasId(['{manager}', '[TemplateAdmin]']));
> // true
> ]]></js:visible>
> <outline>outline.olnAdministration</outline>
>
> </page>
>
>
> How can we enable Javascript highlighting in CDATA in Eclipse?

There's no way without writing a plug-in. The first steps would be to
identify your XML files as their own content type, otherwise you'd be
treating all CDATA sections in all XML files as JavaScript, which
certainly can't be right. Then it would require similar features as the
org.eclipse.wst.jsdt.web.core plug-in provides to handle the JavaScript
within the page, but as we don't have this working yet for XHTML,
there's not an example yet for doing so. XHTML should be something we
tackle in 3.3, but even then I'm sure changes to allow that flexibility
would need to be added to the XML model for your scenario.

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: Javascript highlighting in CDATA content [message #535960 is a reply to message #534409] Wed, 26 May 2010 13:37 Go to previous message
xemox  is currently offline xemox
Messages: 9
Registered: May 2010
Junior Member
Hi Nitiin, Smile

Thanks for your reply. I started to dig in org.eclipse.wst.jsdt.web.core plug-in in order to understand how syntax coloring works for Javascript.

Initially, for testing purposes what I wanted was just to highlight the content inside the <script2> </script2> element instead of default <script> </script> javascript tags.

I have searched for ''script" tag in the source code and than have changed them accordingly into "script2". These are the places where I have changed:

1. In org.eclipse.wst.jsdt.web.core\JsTranslator.java in :

a. translate() method:
if ((!nh.isEndTag() || nh.isSelfClosingTag()) && (nh.nameEquals("script2"){ ...

b. in translateJSNode() method
if(name==null || !name.trim().equalsIgnoreCase("script2") || !nh.isEndTag()) { ...

2. in org.eclipse.wst.jsdt.web.core \src\org\eclipse\wst\jsdt\web\core\javascript\HTML40Namespac e.java:
public static final String SCRIPT = "SCRIPT2"; //$NON-NLS-1$

3. org.eclipse.wst.jsdt.web.ui \src\org\eclipse\wst\jsdt\web\ui\views\contentoutline\JFaceN odeAdapterForJs.java:

in isJSElementParent() metod:
return (node.hasChildNodes() && node.getNodeName().equalsIgnoreCase("script2"));

4. And similarly relevant 3 places at org.eclipse.wst.html.core files

Afterwards I exported the 3 aforementioned plugins and replaced them with old ones and run Eclipse from Manifest file as "Launch an Eclipse application".

And I opened a testing X/HTML file and typed simple JS code like:
<script2>
function addition()
{
var a = 4;
c = a + 5;
return c;
}
</script2>

But it did not highlight the <script2> content. Now I also missed the syntax coloring in normal <syntax> tags.

1. What I miss? or What did I do wrongly? Could you please enlighten me on this?

2. Most of our javascript code is embedded in XML files with "js:" namespace as follows:

<js:unless><![CDATA[
var favoritesEnabled = session.currentDatabase.getConfigSetting('fdFavoritesEnabled ');
if (favoritesEnabled != null && favoritesEnabled.length > 0 && favoritesEnabled[0] == '1') {
session.getDatabase('om').getView('user.$vwUsers').getDocume nt(session.currentUser.id) != null;
} else {
false;
}
]]></js:unless>



My idea is to check whether each tag starts with "js:" namespace, and than syntax coloring the element with javascript code highligting.

Where can I find namespace handling in JSDT and how can I tell eclipse that it can syntax color all elements with "js:" namespace? And what are the concepts, steps to learn and follow to achieve this? Where can I start? Show me some guidelines.

I would really appreciate your reply. thanks!
Best Regards,
Xemox.




[Updated on: Wed, 26 May 2010 13:42]

Report message to a moderator

Previous Topic:CVS resource of org.eclipse.wst.jsdt.ui is virus infected?
Next Topic:Eclipse error during geneation of java source code from wsdl.
Goto Forum:
  


Current Time: Fri Oct 31 09:17:12 GMT 2014

Powered by FUDForum. Page generated in 0.02691 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software