[Pmwiki-users] Re: Idea for visual anchors

Christian Ridderström chr
Fri Feb 6 01:04:12 CST 2004


On Thu, 5 Feb 2004, Patrick R. Michaud wrote:

> [[append:Cookbook.VisibleAnchors]]    <--non-functioning demonstration

You know, I didn't see this until just before I was about to send the 
mail... can't say what that means though :-)

> 
> On Thu, Feb 05, 2004 at 10:09:52PM +0100, Christian Ridderstr?m wrote:
> > 
>
> If you want to try it, add to local.php:
> 
>     $LinkPatterns[780]["\\[\\[#$FragmentPattern\\]\\]"] =
>       "<span id='$1' class='$1'><a href='#$1'>&#167;</a></span>";
> 

This didn't work "out of the box", e.g.
	id='$1'
results in something like
	id='#anAnchor'
and I don't think we want the '#' in the name of the anchor?

Instead, I defined
	$FragmentPattern0="(?:[A-Za-z][-.:\\w]*)";

which doesn't contain '#'. From a logical point of view I'd like to split
$FragmentPattern into a separator character and the fragment name.  Maybe
into $FragmentSep $FragmentPattern, but then you'd have to write
"$FragmentSep$FragmentPattern" in most places. A compromise would of 
course be to use the definition of $FragmentPattern0 above, and define:
	$FragmentPattern="$FragmentSep$FragmentPattern";

> I chose &#167; ('?') as the link text,

I went with '@' instead.

> but you can put <img...> or whatever you want, and I used <span> instead
> of <div> because [[##anchor]] might be used in inline text (<div> is block
> markup by default).

I used <span> as you did. Just out of curiosity though, does it matter 
when the block is 'float: left'?

You can see a demonstration of how it works here:
	http://www.lyx.org/~chr/wiki/pmwiki.php?pagename=Anchor.Anchor

and Here's the code:

$HTMLHeaderFmt = "$HTMLHeaderFmt
<style type='text/css'>
span.Anchor { float: left; font-size: small; width: 1.5em; }
</style>";

SDV($AnonymousAnchors, 0);
SDV($AnonymousAnchorPrefix, '');
SDV($FmtAnchorLink, 'FmtAnchorLink');
$FragmentPattern0="(?:[A-Za-z][-.:\\w]*)";
$LinkPatterns[780]["\\[\\[##($FragmentPattern0?)\\]\\]"] = $FmtAnchorLink;

function FmtAnchorLink($pat, $ref, $btext, $out=NULL, $pname=NULL) {
  global $AnonymousAnchorPrefix, $AnonymousAnchors;
  preg_match("/$pat/", $ref, $match);

  $id = ""==$match[1] ? $AnonymousAnchorPrefix.$AnonymousAnchors++ : $match[1];
  return "<span id='$id' class='Anchor'><a href='#$id'>@</a></span>";
}

Any comments on the code? 

If it's reasonable I can add it to the cookbook, perhaps as
	Cookbook.VisibleAnchor
?

/Christian
 
-- 
Christian Ridderstr?m                           http://www.md.kth.se/~chr






More information about the pmwiki-users mailing list