Code, beautiful code!

Note: I accidentally erased this post while playing around. Luckily I had the site open in another window and could recreate it.

I finally found the time to add a syntax highlighter to FlashAnt. 've integrated GeSHi, the excellent Generic Syntax Highlighter (those of you who were on within the last five-ten minutes may have noticed me making test posts to tweak the output.) GeSHi handles a lot more besides ActionScript (and ActionScript 2). In fact, it can highlight over 30 languages, so plugging additional languages in the future will be very easy.

Her's a simple class to demonstrate the new code view:

  1. class HelloWorld
  2. {
  3. private var _msg:String = "I am beautiful!";
  4. function HelloWorld ()
  5. {
  6. trace ( "Hello, world!" );
  7. trace ( msg );
  8. }
  9. public function get msg ()
  10. {
  11. return _msg
  12. }
  13. }

And how you would use it, from an FLA (blatant test of having two code areas in one post, I know!)

  1. // Import the class
  2. import HelloWorld;
  3.  
  4. // Instantiate an instance
  5. new HelloWorld();

Modifying the b2 blog engine to get this to work was not difficult at all. If any of you are running b2, just email me and 'll send you the hack (heck, I might just add PHP highlighting to the blog and post the hack here! Basically, I modified the format_to_post method in b2functions.php to search for <as2>...</as2> tags and run the contents through GeSHi. Then, I surrounded the resulting PRE tag with a DIV ala what VBulletin does on the London MMUG Web Site.

Something tells me this is going to motivate me to post lots more code samples in the future!

Comments