Skip to main content

A simple online tool to add syntax highlighting to JavaScript. For use in your web pages.

- (update: )

Simplistic JavaScript syntax highlighter

This article was first published A long time ago in a galaxy far, far away.... and is kept purely for reference.

Rewritten in this galaxy for the 21st century and available in this article Displaying code in webpages.

JavaScript is required for the text-parser to work.

A rather simple text parser for JavaScript. All occurrences of the symbols: <, >, " and & are replaced with character entities. then the syntax is highlighted. No checks are made for valid code.

CSS

Highlight colours are defined by:


<style type="text/css">
span.comment  {color:#060; font-weight:normal}
span.oper     {color:#006; font-weight:normal}
span.var      {color:#600; font-weight:normal}
span.func     {color:#606; font-weight:normal}
span.num      {color:#300; font-weight:bold}
span.string   {color:#066; font-weight:normal}
span.reg      {color:#666; font-weight:normal}
</style>
    

Credits

Function addEvent()
The usual onload handler from Simon Willison
Function syntaxHighlight()
A vaguely modified version of Syntax highlighter for JavaScript 1.2 from howtocreate.co.uk

Socialise: