[Mono-docs-list] Web browser hyperlink cleanup
Fawad Halim
fawad@fawad.net
Wed, 15 Oct 2003 00:25:46 -0500
This is a multi-part message in MIME format.
--------------040209010502010103060807
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi,
Attached is a patch that makes monodoc.ashx fix the <a> links on the
server side instead of using javascript on the client side.
Advantages:
* Will (hopefully) make the docs Google-able (spiders don't do javascript).
* It should also make it possible to use htdig or swish-e to index and
search the docs.
* Documents are browseable from lynx now
* prefix munging no longer neccesary for non-IE browsers.
Disadvanges:
* More processing on server.
* Uses regex instead of DOM.
Regards
-fawad
--------------040209010502010103060807
Content-Type: text/plain;
name="Monodoc_ashx.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Monodoc_ashx.diff"
Index: browser/web/monodoc.ashx
===================================================================
RCS file: /mono/monodoc/browser/web/monodoc.ashx,v
retrieving revision 1.18
diff -r1.18 monodoc.ashx
23a24
> using System.Text.RegularExpressions;
197a199
> string requestPath;
207,214d208
< objs = document.getElementsByTagName('a');
< for (i = 0; i < objs.length; i++) {
< e = objs [i];
< if (e.href == null) continue;
<
< objs[i].href = makeLink (objs[i].href);
< }
<
252c246,249
< ctx.Response.Write (content);
---
> // Set up object variable, as it's required by the MakeLink delegate
> requestPath=ctx.Request.Path;
> string content_changed=MakeLinks(content);
> ctx.Response.Write (content_changed);
257a255,282
>
> string MakeLinks(string content)
> {
> MatchEvaluator linkUpdater=new MatchEvaluator(MakeLink);
> if(content.Trim().Length<1|| content==null)
> return content;
> try
> {
> string updatedContents=Regex.Replace(content,"(<a[^>]*href=['\"])([^'\"]+)(['\"][^>]*>)", linkUpdater);
> return(updatedContents);
> }
> catch(Exception e)
> {
> return content+"!<!--Exception:"+e.Message+"-->";
> }
> }
>
> // Delegate to be called from MakeLinks for fixing <a> tag
> string MakeLink(Match theMatch)
> {
> string updatedLink=String.Format("{0}{1}?link={2}{3}",
> theMatch.Groups[1].ToString(),
> requestPath,
> HttpUtility.UrlEncode(theMatch.Groups[2].ToString().Replace("file://","")),
> theMatch.Groups[3].ToString());
> return updatedLink;
> }
>
--------------040209010502010103060807--