Syntax HighLighter in JavaScript : Syntax HighLighter « GUI Components « JavaScript DHTML

Syntax HighLighter in JavaScript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
  <meta name="author" content="Dean Edwards"/>
  <!-- keeping code tidy!! -->
  <meta name="copyright" content="&copy; copyright 2005, Dean Edwards"/>
  <link rel="stylesheet" href="star-light.css" type="text/css"/>

<p>A configurable syntax-highlighter.</p>

<pre class="html">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
&lt;html xmlns="" xml:lang="en"&gt;
  &lt;title&gt;Sample HTML&lt;/title&gt;

  &lt;meta name="author" content="Dean Edwards"/&gt;
  &lt;!-- keeping code tidy!! --&gt;
  &lt;meta name="copyright" content="&amp;copy; copyright 2005, Dean Edwards"/&gt;
  &lt;style type="text/css"&gt;
   body {color: black;}
  &lt;script type="text/javascript"&gt;
   onload = function() {
      // do something

<pre class="css">
@import url(;

/* comment */
@media screen {
  div.document {
    background-color: #eee;
    width: 0;

<pre class="javascript">
// this is a "comment"
/* so is this */
var string = "/* string */";
alert('Hello \'Dean\'!');
function getText(a, b, c) {
  if (a && b) return a + b + c.toString();

<pre class="php">
// author:
$string = "/* string */";
print('Hello Dean!');
function getText($a, $b, $c) {
  return $a + $b + $c;

<pre class="email">
So said the script writer:
&gt; I like *bold* text! :-)
&gt; But the other man said:
&gt;&gt; I like /italicised/ text. :(
&gt;&gt; A third fellow chimed in:
&gt;&gt;&gt; I think _underlined_ text should suit you both. ;-)
&gt;&gt; _Hey_! He's right! :-)
&gt; _Groovy_. ;-)

<pre class="vbscript">
Rem this is a "comment"
' so is this
Function MyHex(ByVal Number)
  Dim Sign
  Const HexChars = "0123456789ABCDEF"
  Sign = Sgn(Number)
  Number = Fix(Abs(CDbl(number)))
  If Number = 0 Then
    MyHex = "0"
    Exit Function
  End If
  While Number > 0
    MyHex = Mid(HexChars, 1 + (Number - 16 * Fix(Number / 16)), 1) & MyHex
    Number = Fix(Number/16)
  If Sign = -1 Then MyHex = "-" & MyHex
End Function

<pre class="tsql">
  @table_name sysname,
  @column_name sysname,
  @nth int

--Date written: December 23rd 2000
--Purpose: To find out the nth highest number in a column.

SET @table_name = RTRIM(@table_name)
SET @column_name = RTRIM(@column_name)

DECLARE @exec_str CHAR(400)
IF (SELECT OBJECT_ID(@table_name,'U')) IS NULL
  RAISERROR('Invalid table name',18,1)


Related examples in the same category

1.CodePress - Real Time Syntax Highlighting Editor written in JavaScript
2.Syntax Highlighter 1.5.0