[R] R-code in html help pages: syntax highlighting

Duncan Murdoch murdoch at stats.uwo.ca
Mon Mar 16 20:04:20 CET 2009


On 3/16/2009 2:50 PM, Romain Francois wrote:
> Duncan Murdoch wrote:
>> On 3/16/2009 1:49 PM, Jose Quesada wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>  
>>> Hi,
>>>
>>> A follow up to my previous post. It'd be good to have syntax
>>> highlighting in the html help pages. 
>>
>> This needs two things:  making the highlight program available to R, 
>> and then adding it to the Rd to HTML conversion code.  In current 
>> releases that conversion is done in Perl code, but with R 2.9 an 
>> R-based converter will be available (but not used by default; too many 
>> CRAN packages have too many errors in their Rd files, and the new 
>> converter is more sensitive to such things).  So sometime after 2.9.0 
>> is released, it would seem like a reasonable project to modify the 
>> conversion to allow for syntax highlighting.
>>
>> One likely complaint is that the highlighting will be inaccurate. 
>> Typically highlighters just have a list of things they know to be 
>> important names, they don't actually take scoping rules into account 
>> (so mean gets highlighted as a built in function even when used as
>>
>> mean <- (x + y)/2
>>
>> for example).  So it would be interesting if someone wanted to do the 
>> work to make a syntax highlighter that was accurate.  I'd say the R 
>> core work on something like this would be to provide the hook for a 
>> user to link in their own favourite highlighter; I doubt if we'd want 
>> to take on the bitching that the inaccurate highlighting would attract.
> Hi Duncan,
> 
> It would be pretty easy to use the output from the R parser (which is 
> never wrong, is it?), and dump some markup out of it. For example the 
> showTree function in codetools dumps an R expression as Lisp, this is 
> not too far from generating html, or any other markup.
> 
> As this sounds like fun, I'll volunteer to do something about this. 
> Another advantage is that we can imagine to plug hyperlinks in  R code 
> that lives in html help pages.
> 


That sounds great.  I'd be happy to work with you to add hooks to the 
conversion functions so your highlighters can be called (but not for a 
few weeks:  we're at a very busy time of year here).  But if you want to 
get started, and figure out what you need, getting in touch with me in 
early April would be fine.

Duncan Murdoch




More information about the R-help mailing list