JavaScript-based Ruby lexer/parser for CSS syntax highlighting?

P

Phrogz

I'm looking for a JS library that will find <code class="ruby"> (or
otherwise-specified) elements on an HTML page and wrap bits in <span
class="keyword">...</span> 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).
 
L

Logan Capaldo

P

Phrogz

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top