Examples 

Shipped Examples 

Python code snippet. This source-highlight filtered block:

[python]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
''' A multi-line
    comment.'''
def sub_word(mo):
    ''' Single line comment.'''
    word = mo.group('word')     # Inline comment
    if word in keywords[language]:
        return quote + word + quote
    else:
        return word
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Renders this highlighted source code:

''' A multi-line
    comment.'''
def sub_word(mo):
    ''' Single line comment.'''
    word = mo.group('word')     # Inline comment
    if word in keywords[language]:
        return quote + word + quote
    else:
        return word

Ruby code snippet with line numbering. This source-highlight filtered block:

[ruby,numbered]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# Useful Ruby base class extensions.
#

class Array

  # Execute a block passing it corresponding items in
  # +self+ and +other_array+.
  # If self has less items than other_array it is repeated.

  def cycle(other_array)  # :yields: item, other_item
    other_array.each_with_index do |item, index|
      yield(self[index % self.length], item)
    end
  end

end

if $0 == __FILE__
  # Array#cycle test
  # true => 0
  # false => 1
  # true => 2
  # false => 3
  # true => 4
  puts 'Array#cycle test'
  [true, false].cycle([0, 1, 2, 3, 4]) do |a, b|
    puts "#{a.inspect} => #{b.inspect}"
  end
end
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Renders this highlighted source code:

00001: #
00002: # Useful Ruby base class tension's.
00003: #
00004:
00005: class Array
00006:
00007:   # Execute a block passing it corresponding items in
00008:   # +self+ and +other_array+.
00009:   # If self has less items than other_array it is repeated.
00010:
00011:   def cycle(other_array)  # :yields: item, other_item
00012:     other_array.each_with_index do |item, index|
00013:       yield(self[index % self.length], item)
00014:     end
00015:   end
00016:
00017: end
00018:
00019: if $0 == __FILE__
00020:   # Array#cycle test
00021:   # true => 0
00022:   # false => 1
00023:   # true => 2
00024:   # false => 3
00025:   # true => 4
00026:   puts 'Array#cycle test'
00027:   [true, false].cycle([0, 1, 2, 3, 4]) do |a, b|
00028:     puts "#{a.inspect} => #{b.inspect}"
00029:   end
00030: end

Extra Examples 

Example 1. C/C++ Header file

/* cmdline.h */

#ifndef CMDLINE_H
#define CMDLINE_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#ifndef CMDLINE_PARSER_PACKAGE
#define CMDLINE_PARSER_PACKAGE PACKAGE
#endif

struct gengetopt_args_info
{
  const char *help_help; /* Print help and exit help description.  */
  const char *version_help; /* Print version and exit help description.  */
  char * input_arg;     /* input file. default std input.  */
  char * input_orig;    /* input file. default std input original value given at command line.  */

  int check_outlang_given ;     /* Whether check-outlang was given.  */
  int failsafe_given ;  /* Whether failsafe was given.  */
  int debug_langdef_given ;     /* Whether debug-langdef was given.  */
  int show_regex_given ;        /* Whether show-regex was given.  */

  char **inputs ; /* unamed options */
  unsigned inputs_num ; /* unamed options number */
} ;

extern const char *gengetopt_args_info_purpose;
extern const char *gengetopt_args_info_usage;
extern const char *gengetopt_args_info_help[];

int cmdline_parser (int argc, char * const *argv,
  struct gengetopt_args_info *args_info);
int cmdline_parser_file_save(const char *filename,
  struct gengetopt_args_info *args_info);

void cmdline_parser_print_help(void);
void cmdline_parser_print_version(void);

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* CMDLINE_H */

Example 2. C/C++ source file

using namespace std;

// global output stream
ostream* sout;

#ifdef BUILD_AS_CGI
#include "envmapper.h"
#endif // BUILD_AS_CGI

unsigned int line_num_digit = 0; // num of digits to represent line number

gengetopt_args_info args_info ;     // command line structure

static void print_cgi_header();
static void run_ctags(const string &cmd);

StartApp::StartApp() :
    docgenerator(0), formatter(0), preformatter(0),
  langmap(new LangMap), outlangmap(new LangMap), generator_factory(0),
  entire_doc (0), verbose (0), cssUrl (0),
  use_css (0), is_cgi (0), gen_version(true),
  generate_line_num(false), generate_ref(false)
{
}

int
StartApp::start(int argc, char * argv[])
{
  char *docTitle;
  char *docHeader; // the buffer with the header
  char *docFooter; // the buffer with the footer
  const char *header_fileName = 0;
  const char *footer_fileName = 0;
  unsigned i;
  int v;
  int tabSpaces = 0;

#ifdef BUILD_AS_CGI
  // map environment to parameters if used as CGI
  char **temp_argv;
  temp_argv = map_environment(&argc, argv);
  is_cgi = temp_argv != argv;
  argv = temp_argv;
#endif // BUILD_AS_CGI

  if((v = cmdline_parser(argc, argv, &args_info)) != 0)
    // calls cmdline parser. The user gived bag args if it doesn't return -1
    return EXIT_FAILURE;

  if (args_info.help_given)
    {
      cout << "GNU ";
      cmdline_parser_print_help ();
      print_reportbugs ();
      return EXIT_SUCCESS;
    }

  printMessage( argv[0] ) ;

  if (verbose) {
    printMessage("command line arguments: ");
    for (int i = 0; i < argc; ++i) {
      printMessage(argv[i]);
    }
  }
}

Example 3. Java source file

/*
  This is a classical Hello program
  to test source-highlight with Java programs.

  written by
  Lorenzo Bettini
*/

package hello;

import java.io.* ;

/**
 * <p>
 * A simple Hello World class, used to demonstrate some
 * features of Java source highlighting.
 * </p>
 * TODO: nothing, just to show an highlighted TODO or FIXME
 *
 * @author Lorenzo Bettini
 * @version 2.0
 */
public class Hello {
    int foo = 1998 ;
    int hex_foo = 0xCAFEBABE;
    boolean b = false;
    Integer i = null ;
    char c = '\'', d = 'n', e = '\\' ;
    String xml = "<tag attr=\"value\">&auml;</tag>", foo2 = "\\" ;

    public static void main( String args[] ) {
        // just some greetings ;-)  /*
        System.out.println( "Hello from java2html :-)" ) ;
        System.out.println( "\tby Lorenzo Bettini" ) ;
        System.out.println( "\thttp://www.lorenzobettini.it" ) ;
        if (argc > 0)
            String param = argc[0];
        //System.out.println( "bye bye... :-D" ) ; // see you soon
    }
}

Example 4. Perl source file

# Here an extract of package MIME::Lite::HTML

package MIME::Lite::HTML;

# module MIME::Lite::HTML : Provide routine to transform a HTML page in
# a MIME::Lite mail
# Copyright 2001 A.Barbet alian@alianwebserver.com.  All rights reserved.

use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use MIME::Lite;
use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;

@ISA = qw(Exporter);
@EXPORT = qw();

my $LOGINDETAILS

#------------------------------------------------------------------------------
# redefine get_basic_credentials
#------------------------------------------------------------------------------
{
    package RequestAgent;
    use vars qw(@ISA);
    @ISA = qw(LWP::UserAgent);

    sub get_basic_credentials
        {
          my($self, $realm, $uri) = @_;
          # Use parameter of MIME-Lite-HTML, key LoginDetails
          if (defined $LOGINDETAILS) { return split(':', $LOGINDETAILS, 2); }
          # Ask user on STDIN
          elsif (-t)
            {
                my $netloc = $uri->host_port;
                print "Enter username for $realm at $netloc: ";
                my $user = <STDIN>;
                chomp($user);
                # 403 if no user given
                return (undef, undef) unless length $user;
                print "Password: ";
                system("stty -echo");
                my $password = <STDIN>;
                system("stty echo");
                print "\n";  # because we disabled echo
                chomp($password);
                return ($user, $password);
            }
          # Damm we got 403 with CGI (use param LoginDetails)  ...
          else { return (undef, undef) }
        }
  }

Example 5. Php source file

<?php

class imgHandling
{
    public static function genThumbnail($mx, $my, $upload_dir, $fileName, $fileNameNew="")
    {
        if (!$fileNameNew) $fileNameNew = $fileName;
        $thumbnail = new sfThumbnail($mx, $my);
        $thumbnail->loadFile($upload_dir. $fileName);
        $thumbnail->save(sfConfig::get('sf_upload_dir').'/thumbnails/'.$fileNameNew, 'image/png');
    }
}

Example 6. Shell source file

#!/bin/bash
#
# rc file for automount using a Sun-style "master map".
# We first look for a local /etc/auto.master, then a YP
# map with that name
#

FLAGS="defaults 21"
DAEMON=/usr/sbin/automount
prog=`basename $DAEMON`
initdir=/etc/init.d

test -e $DAEMON || exit 0

system=unknown
if [ -f /etc/debian_version ]; then
        system=debian
elif [ -f /etc/redhat-release ]; then
        system=redhat
else
        echo "$0: Unknown system, please port and contact autofs@linux.kernel.org" 1>&2
        exit 1
fi

# Check for all maps that are to be loaded
function getfilemounts()
{
    if [ -f /etc/auto.master ] ; then
        cat /etc/auto.master | awk '{print $0}' | sed -e '/^#/d' -e '/^$/d' | (
        while read auto_master_in
        do
            if [ "`echo $auto_master_in | grep '^\+'`" = "" ]; then
                echo $auto_master_in
            else
                cat /etc/auto.master | grep '^\+' | sed -e '/^#/d' -e '/^$/d' | (
                    while read map options; do
                        catnismap `echo "$map" | sed -e 's/^\+//'` $options
                    done
                )
            fi
        done
        )
    fi
}

function getldapmounts()
{
    if [ -x /usr/lib/autofs/autofs-ldap-auto-master ]; then
        [ ! -z $LDAPURI ] && export LDAPURI="$LDAPURI"
        [ ! -z $LDAPBASE ] && export LDAPBASE="$LDAPBASE"
        /usr/lib/autofs/autofs-ldap-auto-master 2> /dev/null
        /usr/lib/autofs/autofs-ldap-auto-master -m automountMap \
            -e automount -n ou -k cn -v automountInformation 2> /dev/null
    fi
}

case "$1" in
start)
        echo -n 'Starting automounter:'
        ;;
status)
        status
        ;;
getmounts)
        getmounts
        ;;
active)
        alive
        ;;
*)
        echo "Usage: $initdir/autofs {start|stop|restart|reload|status|getmounts|active}" >&2
        exit 1
        ;;
esac

Example 7. Tex Document

\documentstyle{article}
% The following definition changes the font that LaTeX
% uses for the 'Large' font.  I have introduced a typo
% into the definition, "\fontsiz" should be "\fontsize".
% The  first time a \Large font is requested, an error will occur.
\renewcommand{\Large}{\fontsiz{17}{20pt}\selectfont}
\begin{document}

This text precedes the first section header.

% Note: LaTeX uses the \Large font in section
% headers...this will fail in a confusing way
% because the error is deep within the definition
% of \section where \Large is used...
\section{First Section}

This is the first and only sentence of the first section.

%%% itemize

\begin{itemize}

  \item This is item 1 and our task has just begun. Blank lines
        before an item have no effect.

  \item This is item 2 and we shall limit to just this few.

        A blank line within an item does create a new paragraph, using the
        indentation of the itemize environment.

        \begin{itemize}

        \item A second (nested) itemized list changes the bullet
          and indents another level.
        \end{itemize}

\end{itemize}

%%% enumerate

\begin{enumerate}

  \item This is item 1, and we are having fun.
  \item This is item 2, and it's time to number anew.
  \begin{enumerate}
    \item Back to item 1, but we are not yet done.
    \item Two is new.
        \begin{enumerate}
        \item One again!
        \item Two (b) or knot 2b?
        \end{enumerate}
  \end{enumerate}
\end{enumerate}

%%% description

 \begin{description}
 \item [Basic Document Preparation.] Knowing how to setup ...
 \item [Making Tables.] \LaTeX~ provides a means ...
 \item [Bibliography.] Knowing how to create a bibliography ...
 \item [Mathematics.] This is the power of \LaTeX~ and one ...
 \item [Graphics.] This has progressed a great deal in the ...
 \item [Other.] There are a great many things to learn ...
 \end{description}

\end{document}

Example 8. Xml file

<xml>
  <table>
    <rec id="1">
      <numField>123</numField>
      <stringField>String Value</stringField>
    </rec>
    <rec id="2">
      <numField>346</numField>
      <stringField>Text Value</stringField>
    </rec>
    <rec id="3">
      <numField>-23</numField>
      <stringField>stringValue</stringField>
    </rec>
  </table>
</xml>