public
Description: A compact, extensible code highlighter written in JavaScript
Homepage:
Clone URL: git://github.com/danwrong/code-highlighter.git
name age message
file README Mon Sep 21 01:53:12 -0700 2009 updated readme [danwrong]
file applescript.js Mon Sep 21 01:51:51 -0700 2009 added Python and AppleScript, updated Tuby and ... [danwrong]
file code_highlighter.js Wed Nov 08 05:36:31 -0800 2006 fixed bug with class name not recognising white... [danwebb]
file css.js Thu Aug 17 10:20:26 -0700 2006 initial import. git-svn-id: http://svn.danwe... [danwebb]
file html.js Thu Aug 17 10:20:26 -0700 2006 initial import. git-svn-id: http://svn.danwe... [danwebb]
file index.html Thu Aug 17 10:20:26 -0700 2006 initial import. git-svn-id: http://svn.danwe... [danwebb]
file javascript.js Mon Sep 21 01:51:51 -0700 2009 added Python and AppleScript, updated Tuby and ... [danwrong]
file python.js Mon Sep 21 01:51:51 -0700 2009 added Python and AppleScript, updated Tuby and ... [danwrong]
file ruby.js Mon Sep 21 01:51:51 -0700 2009 added Python and AppleScript, updated Tuby and ... [danwrong]
file stylesetguide.html Thu Aug 17 10:20:26 -0700 2006 initial import. git-svn-id: http://svn.danwe... [danwebb]
file test.html Thu Aug 17 10:20:26 -0700 2006 initial import. git-svn-id: http://svn.danwe... [danwebb]
README
CodeHighlighter 0.4 by Dan Webb
-------------------------------

CodeHighlighter is a lightweight, unobstrusive and fully configurable script for displaying code examples highlighted in 
a way similar to the way many text editors highlight code. It weighs in at just under 4K, allows users to configure 
their own style sets so that you can highlight any language you like and is deployable simply by attaching it to a page 
with the script tag and adding class names as hooks. It should also play nicely with any other scripts on your page as 
it has a tiny footprint on the global namespace.

Many thanks to Dean Edwards who's star-light behaviour inspired this.
Deploying the script

   1. Add a <script> tag for CodeHighlighter.js and a script tag for each of the code types you want to highlight on 
   your page. At this time there are only very basic style sets for JavaScript, CSS and HTML. But it's easy to make your 
   own for any language you like if you know regular expressions. Let me know if you do and I'll link to them.
   2. Add an appropriate class to each <code> element that contains code. 'javascript', 'ruby', 'css' or 'html' will do 
   the trick.
   3. Define CSS styles for each code element, the script simply parses the code and wraps a <span> tag around each 
   element with the appropriate class name. You just need to write CSS to style the code the way you want. No 
   programming or weirdness required. See the source of this code as an example.

Testing

Known to work on:

    * IE 5.5+ PC
    * Firefox 1.0/Mozilla 1.3 + PC
    * Opera 7.23 + PC
    * Netscape 7.2 PC

Known to degrade well on:

    * IE 5.0 PC
    * Safari Mac (Until it supports functions in String#replace())

Any other feedback for any other browser would be greatly apprieciated. Please email Dan Webb at dan[at]danwebb[dot]net. 
Have a look through the small examples below.
Creating your own style sets for other languages

Have a look at this guide to creating style sets.

Contributors
------------

Python and AppleScript highlighters by Travis Cripps (http://trav.is)