Weird Looking: Syntax Highlighting Test

Syntax Highlighting Test

tags: none
I’ve tried to be somewhat minimalistic with the syntax highlighting.  These are examples of code I’ve written highlighted.

html
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>WeirdLooking: Syntax Highlighting Test</title>
<link title="Blog - RSS 2.0" type="application/rss+xml" rel="alternate" href="http://www.weirdlooking.com/rss" />
<link title="Blog - Atom 1.0" type="application/atom+xml" rel="alternate" href="http://www.weirdlooking.com/atom" />
</head>
<body>

<h1 id="title"><a href="/" title="WeirdLooking.com"><span>WeirdLooking</span></a>: <span>BBCode Enhancements</span></h1>
</body>
</html>


css
body {
 padding
: 0px;
 margin
: 0px;
 background
: #F5F5F5;
 font-family
: "bitstream vera sans", verdana, sans-serif;
 color
: #000000;
 font-size
: 0.8em;
 line-height
: 1.3;
}
h2
{
 margin
: 0px;
 font-size
: 1em;
}
img
{
 border
: 0px;
}


cpp
template<class ItemType>
void updateTree(TreeType<ItemType>& tree, ofstream& out, ifstream& update)
{
 int action;
 char value;
 out << "Updating tree..." << endl;
 while (update)
 {
   update >> action;
   update >> value;
   if (!update)
   {
     out << endl << endl;
     return;
   }
   if (action)
     addToTree(tree, out, value);
   else
     deleteFromTree(tree, out, value);
 }
}


java
package ChatClient;
import java.awt.*;

public class LinkPane extends Canvas
{
 Image img = null;
 String url = null;

 public LinkPane()
 {
 }

 public LinkPane(Image i)
 {
   img = i;
 }

 public void setImage(Image i)
 {
   img = i;
   repaint();
 }

 public void paint(Graphics g)
 {
   if (img != null)
     g.drawImage(img, 0, 0, size().width, size().height, this);
 }
}


javascript
function noteProcess()
{
 if (noteReq.readyState == 4)
 {
   div = document.getElementById("notebody");
   fillDiv(div, noteReq.responseXML, xslReq.responseXML);
   if (window.XMLHttpRequest)
   {
     div = document.getElementById("firefoxsucks-text");
     div.innerHTML = noteReq.responseXML.firstChild.childNodes[4].firstChild.data;
     div = document.getElementById("firefoxsucks-subject");
     div.innerHTML = noteReq.responseXML.firstChild.childNodes[3].firstChild.data;
   }
   noteReq = null;
 }
}


perl
#!/usr/bin/perl

use Image::Magick;

print "Content-type: text/plain\n\n";

print "Doing file conversions...\n\n";
foreach(glob('*.favicon'))
{
 $image = Image::Magick->new;
 print "Converting $_\n";
 $_ =~ /(\d+)\.favicon/;
 $id = $1;
#one of these has to work...
 open(IMAGE, $_);
 $x = $image->Read(filename=>'icon:', file=>\*IMAGE);
 close(IMAGE);
 open(IMAGE, $_);
 $x = $image->Read(filename=>'png:', file=>\*IMAGE);
 close(IMAGE);
 open(IMAGE, $_);
 $x = $image->Read(filename=>'gif:', file=>\*IMAGE);
 close(IMAGE);
 $image->Write(filename=>"$id.png", size=>'16x16');
 $image = undef;
 unlink($_);
}


php
<?php
 function basecon($number, $base)
 {
   $digits = $ret = "";
   while (pow($base, $digits) < $number) $digits++;
   for (;$digits>=0;$digits--)
   {
     $pow = pow($base, $digits);
     $val = floor($number / $pow);
     $ret .= ($val < 10) ? $val : chr($val + 55);
     $number -= ($number < $pow) ? 0 : $pow * $val;
   }
   return preg_replace("/^0*/", "", $ret);
 }
 for ($base = 2; $base <= 16; $base++)
   print basecon(255, $base)."\n";
?>


sql
select * from player_stats where kills > 0 and deaths > 0 order by -(skill+bonus)

xml
<?xml version="1.0" encoding="utf-8"?>
<area>
 <name>Sithrang's Lair</name>
 <builders>Palrich</builders>
 <lvnum>7950</lvnum>
 <uvnum>8049</uvnum>
 <credits>[HERO+] Palrich Sithrang's Lair</credits>
 <security>1</security>
 <minlevel>91</minlevel>
 <npc vnum="7950">
   <level>101</level>
   <name>elf sithrang</name>
   <short>Sithrang</short>
 </npc>
</area>


bbcode
[b]this is some bold text[/b][i]this is some italic text [b]and this is bold italic[/b][/i]
[img=some alt text]address[/img]
[url=address]link text[/url]


c#
 // that .Substring(1) is ugly, but I couldn't figure out a better way to get
 // the local path from file://localhost/C:/whatever.
 public static string FileNameFromUri(string address)
 {
   Uri uri = new Uri(address);
   if (uri.IsFile && uri.Host == "localhost")
     return System.Web.HttpUtility.UrlDecode(uri.PathAndQuery).Substring(1);
   throw new Exception("URI does not point to a local file");
 }

Comments

Apr 26, 2006 10:37pm
What? No ColdFusion?
Apr 26, 2006 10:55pm
ColdFusion is for girls and lesser men.

Leave a comment


Accepts BBCode with a few enhancements.