phoboslab

Syntax Highlighting in 1023 bytes of JavaScript

My entry for the JS1k contest is a JavaScript Syntax Highlighter implemented in 1023 bytes of JavaScript – just one byte short of the contest limit. I also submitted an uncompressed and somewhat more readable version of the source.

The highlighter recognizes keywords, strings, comments (single and multi line), numbers, regexp and punctuations. And as far as I can tell, it works perfectly. It handles escaped characters as well as /* "strings" in comments */ and "comments // in strings" correctly.

I really doubt that I'm going to win anything with this though, as there are already many other unbelievably awesome demos.

Update: Stripped a few more bytes (1005 now) and formatted the source so it's actually readable. I also made the script a Quine – a program that prints its own source. You can find the new version here.

Monday, August 9th 2010
Tags: JavaScript, Web Technology

1 Comment:

#1: Lee – Monday, August 9th 2010, 23:34

*sniff, it's so pretty xD

Post a Comment:

Comment: (Required)

(use <code> tags for preformatted text; URLs are recognized automatically)

Name: (Required)

URL:

Please type phoboslab into the following input field or enable Javascript. This is an anti-spam measure. Sorry for the inconvenience.