On Jan 13, 2008, at 08:54 AM, Phlip wrote:
> Core Rubies:
>
> I feel like syntax-highlighting some Ruby code, just the same way as  
> RDoc
> does.
>
> (Put another way, I'm trying to find a way to extend RDoc.)
>
> So if I have some Ruby, such as 'foo(42)', how do I parse that with  
> RDoc::
> RubyParser, to create a stream of tokens? And how do I route those  
> tokens
> into Generator::HTMLGenerator, and get a string of HTML
> containing 'foo(42)' with the correct colors?
>
> The source code is kind'a snarled together, and I can't find the  
> correct
> entry points!

To have RDoc parse a chunk of ruby, call RDoc::RubyParser#scan.  This  
will fill in the RDoc::TopLevel object you provide, but I don't know  
how to pull the source back out.  Hunting through  
RDoc::Generator::HTML might help there.

You may have to wrap your source up in some method, too.