[Pmwiki-users] Re: Idea for visual anchors
Patrick R. Michaud
pmichaud
Fri Feb 6 11:35:44 CST 2004
On Fri, Feb 06, 2004 at 09:03:57AM +0100, Christian Ridderstr?m wrote:
> On Thu, 5 Feb 2004, Patrick R. Michaud wrote:
>
> 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?
Oh, sorry about that. The code I sent works in 0.6, because the
FragmentPattern in 0.6 has been changed to capture the part
of the pattern after the '#' in it automatically. You're right
that it doesn't work in 0.5, instead it should've been:
$LinkPatterns[780]["\\[\\[##([A-Za-z][-.:\\w]*)\\]\\]"] =
"<span id='$1' class='$1'><a href='$1'>§</a></span>";
> 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?
Element ids cannot begin with a digit, so having $AnonymousAnchorPrefix
default to '' leads to invalid XHTML.
Pm
More information about the pmwiki-users
mailing list