Tags:
create new tag
, view all tags
It has bothered me for a long, long time that the link rendering is pretty horrible. It has forced me to make nasty assumptions and nastier code in several plugins.

By link handling I mean the process by which syntax that TWiki recognises as "a link" gets transformed into HTML.

At the moment this process is hard-coded into Render.pm, so if a extension wants to intercept the process, it has a hard time. In fact, the only thing it can do is to post-process the text of the topic and try to recognise links or, worse, take over the entire rendering process itself.

It would be a lot nicer if extensions had a way to attach a listener to the rendering process that gets activated when a link is processed. Let's say, for example, we want to have a publish plugin that checks for internal dangling links, and for external links to URLs in China:

sub linkHandler {
    my( $type, $url, $params ) = @_;

    if ($type eq 'internal') {
        $url =~ m/(\w+)/(\w+)($|?|#)/;
        if (!TWiki::Func::topicExists($1, $2)) {
            # override the default link handling
            die "Bad link $web.$topic";
        }
        # override the default handling with our own URL
        return "publish_dir/$1/$2.html";
    } elsif ($url =~ /\.cn/) {
        die "Illegal link to China";
    }
    return undef; # allow default handling of the link
}
There are many ways you could use this; for example, finding orphans, auditing, rewriting links, logging etc etc.

Going via the standard plugins handler mechanism may not be the best idea, for two reasons:

  1. Extensions other than Plugins may want to register a listener
  2. Performance

-- Contributors: CrawfordCurrie

Discussion

 
Topic revision: r1 - 29 May 2006 - 17:32:39 - CrawfordCurrie
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback