JavaScript-based Ruby lexer/parser for CSS syntax highlighti

I’m looking for a JS library that will find (or
otherwise-specified) elements on an HTML page and wrap bits in … type elements for CSS syntax coloring of
the original source.

I’ve found two JS-based syntax highlighters ([1] and [2]), but both
fail on Ruby code like:
foo = “Hello #{ “World” }”

They’re both regexp-based, which is the problem. I’m happy to use them
for quick-n-dirty highlighting, but I’m hoping that someone has
written a lexer/parser that handles more complex situations like this
(even if it doesn’t cover every single edge case).

On Feb 27, 12:43 pm, “Phrogz” [email protected] wrote:
[snip]

I’ve found two JS-based syntax highlighters ([1] and [2]), but both
[/snip]

Oops, forgot to attach the references:
[1] http://www.dreamprojections.com/SyntaxHighlighter/
[2] highlight.js

On Wed, Feb 28, 2007 at 04:50:05AM +0900, Phrogz wrote:

On Feb 27, 12:43 pm, “Phrogz” [email protected] wrote:
[snip]

I’ve found two JS-based syntax highlighters ([1] and [2]), but both
[/snip]

Does it have to be JS? You gonna do client side lexing of ruby in JS? (I
guess it has to be, else you wouldn’t have asked.)

  • forges on anyway *

Sure you can’t use http://coderay.rubychan.de/ instead?

On Feb 27, 3:44 pm, Logan C. [email protected] wrote:

Does it have to be JS? You gonna do client side lexing of ruby in JS? (I
guess it has to be, else you wouldn’t have asked.)

  • forges on anyway *

Sure you can’t usehttp://coderay.rubychan.de/instead?

I could, for sure. That trades bytes over the wire for user’s cpu
time. Sometimes I just really like having code syntax highlighted by
the page, particularly when it’s a tiny snippet as part of a larger
page, and not an entire source file.

I hacked the second library I found to do what I want. Although I’m
annoyed with its speed, it’s working reasonably OK for now. It looks
like I was wrong, that is has some form of ‘real’ lexing applied via a
very incomplete idea about Ruby syntax. If no one has a premade JS
library for this, and if it bothers me enough, I’ll spend some time
understanding its scoping and lexing rules and see if it can make the
jump from string mode back into code mode. My quick hackery to add
some features makes it look possible.