Forum: Ruby JavaScript-based Ruby lexer/parser for CSS syntax highlighti

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
852a62a28f1de229dc861ce903b07a60?d=identicon&s=25 Gavin Kistner (phrogz)
on 2007-02-27 20:46
(Received via mailing list)
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).
852a62a28f1de229dc861ce903b07a60?d=identicon&s=25 Gavin Kistner (phrogz)
on 2007-02-27 20:50
(Received via mailing list)
On Feb 27, 12:43 pm, "Phrogz" <g...@refinery.com> 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] http://softwaremaniacs.org/soft/highlight/en/
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2007-02-27 23:44
(Received via mailing list)
On Wed, Feb 28, 2007 at 04:50:05AM +0900, Phrogz wrote:
> On Feb 27, 12:43 pm, "Phrogz" <g...@refinery.com> 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?
852a62a28f1de229dc861ce903b07a60?d=identicon&s=25 Gavin Kistner (phrogz)
on 2007-02-27 23:55
(Received via mailing list)
On Feb 27, 3:44 pm, Logan Capaldo <logancapa...@gmail.com> 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.
This topic is locked and can not be replied to.