Saturday, July 10, 2010

Syntax Highlighter Example

Here's my first attempt at using the SyntaxHighlighter from Alex Gorbatchev.

It is one of the most popular sytnax highlighters on the web today. It has been around since 2004 and is still being supported. That's a mere feat in itself.

The example you see below is v2.1 of Alex's excellent tool. If you'd like to copy the source code, it's easy to snag. Move your mouse over the snippet of code and you'll see a toolbar appear. Mouse over the icons to see what your options are: View Source and many more.

<script>
alert("Hello world and good " + timeOfDay() + "!\nIt's gonna be good.  Really good." );

// Determine what time of day is it... in english! 
function timeOfDay(d) {
  if (d.getHours() >= 0 && d.getHours() < 12)
    return "morning";
  else if (d.getHours() >= 12 && d.getHours() < 18)
    return "afternoon";   
  else
    return "evening";     
} // end: timeOfDay
</script>

No comments: