I would implement syntax highligting by adding a javascript to <head>
in repos.xsl. The javascript would identify files ending with
.php|java|et.al. and make those links open a dialog that uses a
syntaxhighlighting tool. I've used
http://code.google.com/p/syntaxhighlighter/ in a different project and
it is simple enough. Adding this kind of behavior to existing HTML is
usually easy with a library like jQuery.
> This project seems to be geared towards providing exactly that
> functionality
> http://qbnz.com/highlighter/index.php
Yes, there should be many libraries like this.
Once a javascript like this is written it can be an optional component
to Repos Style. The intent of the project was originally to make the
SVN listing prettier. We have avoided javascript so far, except in the
proposed multi-repo solution. If someone wants to implement a viewer
script with sytnax highlighting, I'd be happy to add it to the
download page and the source tree.
/Staffan
I didn't have time to test it yet but I might have some input anyway.
On Tue, Sep 30, 2008 at 12:51 AM, sstk <shinys...@gmail.com> wrote:
>
> I've added in some functionality to use http://code.google.com/p/syntaxhighlighter/
> with repos-style-2.0b1
>
> This is my first JS/XSLT page so please bear with me.
> - To get it to work, extract the /Scripts and /Style directory from
> syntaxhighlighter into the repos-web/view directory.
>
> - edit repos.xsl and add the following :
> - in the repos style configuration section add the following
> parameter
> <xsl:param name="syntaxviewUrl"><xsl:value-of select="$static"/
>>view/syntaxview.html</xsl:param>
> - in the template match="file" section
> change the href for open (and the file link) to
> <a id="open:{$id}" class="action" href="{$syntaxviewUrl}?p=https://
> <<servername>>/<<reponame>>/{../@path}/
> {@href}&t={$filetype}">open</a>
>
> couple of things to note here: I was not able to figure out how to get
> https://<<servername>>/<<reponame>>/{../@path}/ populated dynamically.
> Obviously this should be a parameter we read from.
Through browser independent XSLT it is not possible to get current URL
or repository root URL.
> Basically all we are doing here is passing to the syntaxview.html file
> 2 parameters ( 'p' : <<full file path to the source file you want to
> see>>, 't' : <<filetype: for the syntax highlighter to figure out how
> to deal with it>>)
>
> Finally copy the following syntaxview.html into the same directory :
(see original mail)
>
> Somethings I don't understand, if I try to open any source file >2K
> lines (yeah don't ask!), it takes a LONG time, first to download the
> file with xmlhttprequest, and then to format it with
> syntaxhighlighter.
XMLHttpRequest is usually as fast as any page load, so that shouldn't
be a problem. Syntaxhighlighter is probably slow (I guess it is
because traversing and coloring text in javascript is slow). You could
use Firebug (http://getfirebug.com/) to profile javascripts.
>
> anyway if someone can figure out how to get the base url dynamically
> within the xsl file please do let me know.
>
This would require javascript in the xslt. The "open" hrefs could
probably be updated in body onload after inspecting
window.location.href. Or syntaxview.html could use referrer as
discussed in the multi-repo threads (document.referrer in javascript).
I like this solution because it is quite non-intrusive with the actual
highlighting is in an external html file. Maybe instead of modifying
the "open" button there could be a new "view" button, wrapped in
<xsl:if test="$syntaxviewUrl">. That way it would be a matter of
editing the config section of the xslt to switch highlighting on and
off.
/Staffan
It sounds robust. How do you download files now?
/Staffan