Item8556: Local Anchors don't use relative form

Priority: Normal
Current State: Closed
Released In: 1.0.10
Target Release: patch
Applies To: Engine
Reported By: RaymondLutz
Waiting For:
Last Change By: KennethLavrsen
When a local anchor is used:


and then later it is referred to like this [[#AnchorName][Click Here]] Click Here

the rendered output prefixes the anchor with the web and topic names.

<a href="/Tasks/Item8556#AnchorName" class="foswikiCurrentTopicLink">Click Here</a>

Rather than (the desired):

<a href="#AnchorName" class="foswikiCurrentTopicLink">Click Here</a>

If the page is published to PDF with htmldoc, for example, the anchors will point back to the web site that generated the page rather to PDF anchors inside the published document.


sub _renderExistingWikiWord {
    my $currentTopic = '';
    $currentTopic = 'foswikiCurrentTopicLink'
      if ( ( $web eq $this->{session}->{webName} )
        && ( $topic eq $this->{session}->{topicName} ) );

    my @attrs;
    my $href = $this->{session}->getScriptUrl( 0, 'view', $web, $topic );
    if ($anchor) {
        $anchor = $this->makeAnchorName($anchor);

        # Following modified by RCL to leave local anchors alone
        $href = ($currentTopic eq 'foswikiCurrentTopicLink') ? "#$anchor" : "$href#$anchor";


-- RaymondLutz - 17 Feb 2010

The code change seems reasonable.

Even though $href = $currentTopic ? "#$anchor" : "$href#$anchor"; could probably do it since currentTopic is only set if the topic is the current.

But then again. There is often one thing that breaks when you fix something else.

Often I have found myself placing links to the same topic in a topic with the purpose to ensure that when I later copy the text into an email, all links point back to the wiki and not to nowhere.

We need to think through if this does not not goof up other situations.

But the spec is correct. If the user has put only #AnchorName in a square bracket link the result should be just that.

-- KennethLavrsen - 18 Feb 2010

I tried the different combinations I was concerned about and I have no problems for the moment.

I remember 2-3 years ago in the old project that we had an issue related to anchors but I cannot remember what it was which is why I hesitate. But I think the code change is safe. I will try and run with it for a while and see.

-- KennethLavrsen - 18 Feb 2010

I have implemented a fix in both release branch and trunk

-- KennethLavrsen - 18 Mar 2010


ItemTemplate edit

Summary Local Anchors don't use relative form
ReportedBy RaymondLutz
Codebase 1.0.9, trunk
SVN Range
AppliesTo Engine
Priority Normal
CurrentState Closed
Checkins distro:78c04bfed217 distro:a5948079ab4e distro:44ff295bc5b8 distro:10923443d6ae
TargetRelease patch
ReleasedIn 1.0.10
Topic revision: r9 - 08 Sep 2010, KennethLavrsen - This page was cached on 16 Sep 2021 - 17:30.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy