Ace Syntax Highlighter

Now I have configured Ace to work within my editor so It’s time to add the feature of Syntax Highlighter.

Generally, we’ll manually set mode to editor like

editor.mode(‘ace/mode/javascript’);

for this File extension must be known to us so that we can manually add mode but we don’t know the file extension before hand. so we have to use some intermediator which will tell the file extension.

Ace editor already have a built-in functionality

i.e modelist

now How we can use it?
1. Initialize modelist
var modelist = ace.require("ace/ext/modelist");
2. Get the mode for particular file
var mode = modelist.getModeForPath(path).mode;
3. Set the mode to editor
editor.session.setMode(mode);

That’s it, all this is done under javascript file.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s