Download and usage

To use it, get the highlight.js and highligt.css files and call SyntaxHighlighter.highlightDocument(false) for no linenumbers and SyntaxHighlighter.highlightDocument(true) for linenumbers.

The following languages are defined (but it is easy to expand and add languages - see the bottom of the javascript file): c, c#, javascript, sql, php, python, vb.net and win32. Each language can have it's own color scheme by adjusting the css file.

Example


PHP

<?php
/* Comment... */
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os))
{
  echo "Got Irix";
}
if (in_array("mac", $os))
{
  echo "Got mac"; // Also a comment...
}
?>

Javascript

function splitString(stringToSplit,separator)
{
  var arrayOfStrings = stringToSplit.split(separator);
  print('The original string is: "' + stringToSplit + '"');
  print('The separator is: "' + separator + '"');
  print("The array has " + arrayOfStrings.length + " elements: ");

  for (var i=0; i < arrayOfStrings.length; i++)
    print(arrayOfStrings[i] + " / ");
}

var tempestString = "Oh brave new world that has such people in it.";
var monthString = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";

var space = " ";
var comma = ",";

splitString(tempestString, space);
splitString(tempestString);
splitString(monthString, comma);

C

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char **argv)
{
  char buf[1024];
  int n, in, out;

  if(argc != 3)
  {
    fprintf(stderr, "Usage: append SOURCE TARGET\n");
    return 0;
  }

  /* open the first file for reading */
  in = open(argv[1], O_RDONLY);
  /* the second file for writing */
  out = open(argv[2], O_WRONLY|O_APPEND);

  /* copy data from the first file to the second file */
  while((n = read(in, buf, sizeof(buf))) > 0)
    write(out, buf, n);

  return 0;
}

C#

using System;
using System.Windows.Forms;

public class MyForm : Form
{

  void btn1_onclick(object sender, EventArgs e)
  {
    Text = "Sender: " + sender.ToString() + " - Event: " + e.ToString();
  }

  void btn1_onclick2(object sender, EventArgs e)
  {
    Console.WriteLine(String.Format(
	  "Sender: {0} - Event: {1}",
	  sender.ToString(),
	  e.ToString()));
  }

  public MyForm()
  {
    Text = "Hello World";

    Button btn1 = new Button();
    btn1.Text = "Click Me";
    this.Controls.Add(btn1);

    btn1.Click += new EventHandler(btn1_onclick);
    btn1.Click += new EventHandler(btn1_onclick2);
  }

  public static void Main()
  {
    Application.Run(new MyForm());
  }

}

Python

#!/usr/local/bin/python

import string, sys

# If no arguments were given, print a helpful message
if len(sys.argv)==1:
  print 'Usage: celsius temp1 temp2 ...'
  sys.exit(0)

# Loop over the arguments
for i in sys.argv[1:]:
  try: 
    fahrenheit=float(string.atoi(i))
  except string.atoi_error:
    print repr(i), "not a numeric value"
  else:
    celsius=(fahrenheit-32)*5.0/9.0
    print '%i\260F = %i\260C' % (int(fahrenheit), int(celsius+.5))

VB.NET

Imports System

Public Class MainClass

  Shared Sub Main()
    Dim tom As New Employee("Tom", 50000, "111-11-1234")
    Dim sally As New Employee("Sally", 150000, "111-11-2234")

    Dim ourEmployees(1) As PayableEntity
    ourEmployees(0) = tom
    ourEmployees(1) = sally
    Dim anEmployee As PayableEntity
    For Each anEmployee In ourEmployees
      Console.WriteLine(anEmployee.TheName & ": " & anEmployee.TaxID )
    Next

  End Sub
End Class

Public MustInherit Class PayableEntity
  Private m_Name As String
  Public Sub New(ByVal itsName As String)
    m_Name = itsName
  End Sub
  ReadOnly Property TheName() As String
    Get
      Return m_Name
    End Get
  End Property
  Public MustOverride Property TaxID() As String
End Class