setting new mimetypes

Questions on using RSyntaxTextArea should go here.

Moderator: robert

setting new mimetypes

Postby je_bailey » Thu Jul 26, 2012 2:14 pm

The syntax declarations are composed like mimetypes, but don't cover the official versions for scripting languages. Is there a way to add new mimetypes to the system programmtically?
Posts: 7
Joined: Thu Jul 19, 2012 5:54 pm

Re: setting new mimetypes

Postby robert » Sun Jul 29, 2012 4:21 am

If I understand what you're asking, then yes, I believe you could do something like this:

java code:

String defaultPackage = "org.fife.ui.rsyntaxtextarea.modes.";

DefaultTokenMakerFactory tmf = (DefaultTokenMakerFactory)TokenMakerFactory.getDefaultInstance();
tmf.putMapping("text/x-script.perl", defaultPackage + "PerlTokenMaker");
tmf.putMapping("text/x-script.phyton", defaultPackage + "PythonTokenMaker");
tmf.putMapping("text/x-script.elisp", defaultPackage + "LispTokenMaker");
// etc.

This assumes of course you are comfortable hard-coding a little knowledge of the internals of RSTA into your application. FWIW, this particular stuff is exceedingly unlikely to change.
User avatar
Posts: 852
Joined: Sat May 10, 2008 5:16 pm

Re: setting new mimetypes

Postby Guest » Mon Jul 30, 2012 3:16 pm

Thanks, this is what I was looking for.

The problem comes with the difference between the official mimetype for script files and what is commonly accepted as mimetypes (historically because of IE.)

Take javascript as an example, you currently have it's mimetype as "text/javascript", that's technically not correct, the correct mimetype for javascript is "application/javascript". There's a good explanation of why this is at ... -mime-type.

Normally this doesn't matter. For the application that I'm interfacing with, it does official mimetypes, so for me to match up with the syntax highlighting I need to do some parsing. Now, rather than parsing, I'll just add the application based mimetypes once and have done with it.

Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest