How to add JavaFX to SyntaxHighlighter

I got sick and tired of my JavaFX code not having proper syntax highlighting on my blog and in my presentations, so I extended SyntaxHighlighter to do just that.

How to implement it

First, you’ll want to download SyntaxHighlighter or get the Wordpress plugin (and make a donation, it really is a cool piece of work). Next, unzip or otherwise install it. Download my shBrushJavaFX.js and copy it to <install_directory>/scripts

If you’re using the Wordpress plugin, you’ll have to edit the syntaxhighlighter.php file like so:

//About line 112, just after this line
$this->aliases = apply_filters( 'agsyntaxhighlighter_aliases', array(

//Add the following:
'JavaFX'  => array('jfx', 'javafx'),

Now give it a try using the language “javafx” or “jfx”!

JavaFX highlighting demo

def wheelCenterY:Number = stageHeight / 2 - 30;
var winnerId:Integer;
var wheelRotation:Number = 360 on replace {
    //Set winner
    winnerId = ((wheelRotation mod 360) / 360.0 * arr.size()).intValue();
}
var contestants = ["Eric","Fred","Helga"];
insert "Olaf" after contestants[0];
// contestants -> Eric,Olaf,Fred,Helga
delete "Helga" from contestants;
// contestants -> Eric,Olaf,Fred

Download the Javascript code for SyntaxHighlighter 2.0.x or SyntaxHighlighter 1.5.x. Let me know if you see any bugs or have any feedback. Enjoy!

If you liked this post, please help me share it

Responses (2)

  1. Alex G says:

    I recommend upgrading SH to 2.0.296 which fixes green picka-boos on the mac.

    http://alexgorbatchev.com/wiki/SyntaxHighlighter:Changes:2.0.296

    Thnx for using SyntaxHighlighter :)

Leave a Reply