Usage:
[#test] * SandBox * SandBox#test * SampleUndefinedPage#test * [SandBox bracket_wiki] * [SandBox#test bracket_anchored] * [SampleUndefinedPage#test bracket_anchored_edit]
see below for a shorter patch...'
Add $NamedAnchors, $AnchoredLinkPattern to use vars qw();
# Minor options: ... $NamedAnchors = 1; # 0 = no anchors, 1 = enable anchors, 2 = enable but suppress display
sub InitLinkPatterns { ... $QDelim = '(?:"")?'; # Optional quote delimiter (not in output) $AnchoredLinkPattern = $LinkPattern . '#(\\w+)' . $QDelim if $NamedAnchors; $LinkPattern .= $QDelim; ... }
# sub GetPageOrEditLink { sub GetPageOrEditAnchoredLink { my ($id, $anchor, $name) = @_; ... if ($exists) { $id = "$id#$anchor" if $anchor; $name = "$name#$anchor" if $anchor && $NamedAnchors != 2; return &GetPageLinkText($id, $name); } ... }
sub GetPageOrEditLink { my ($id, $name) = @_; return &GetPageOrEditAnchoredLink( $id, "", $name ); }
# Add after sub StoreBracketLink sub StoreBracketAnchoredLink { my ($name, $anchor, $text) = @_;
return &StoreRaw(&GetPageLinkText("$name#$anchor", "[$text]")); }
sub CommonMarkup { ... s/\<code\>((.|\n)*?)\<\/code\>/&StorePre($1, "code")/ige; s/\[\#(\w+)\]/&StoreHref(" name=\"$1\"")/ge if $NamedAnchors; ...
if ($BracketText) { # Links like [URL text of link] s/\[$UrlPattern\s+([^\]]+?)\]/&StoreBracketUrl($1, $2)/geos; s/\[$InterLinkPattern\s+([^\]]+?)\]/&StoreBracketInterPage($1, $2)/geos; if ($WikiLinks && $BracketWiki) { # Local bracket-links s/\[$LinkPattern\s+([^\]]+?)\]/&StoreBracketLink($1, $2)/geos; s/\[$AnchoredLinkPattern\s+([^\]]+?)\]/&StoreBracketAnchoredLink($1, $2, $3)/geos if $NamedAnchors; } } ... if ($WikiLinks) { s/$AnchoredLinkPattern/&StoreRaw(&GetPageOrEditAnchoredLink($1, $2, ""))/geo if $NamedAnchors; s/$LinkPattern/&GetPageOrEditLink($1, "")/geo; } }
Creating an anchor:
Referencing an anchor:
Find this line in the patch for the subroutine CommonMarkup:
s/\[\#(\w+)\]/&StoreHref(" name=\"$1\"")/ge if $NamedAnchors;and replace it with the following lines:
if ($NamedAnchors) { s/\[\:(\w+)\|([^\]]+)\]/&StoreHref(" name=\"$1\"", $2)/ge; s/\[\:(\w+)\]/&StoreHref(" name=\"$1\"")/ge; s/\[(\#\w+)\|([^\]]+)\]/&StoreHref(" href=\"$1\"", $2)/ge; s/\[\#(\w+)\]/&StoreHref(" href=\"#$1\"", $1)/ge; }
See it in action at http://www.IAwiki.net/dev.pl?ScratchPad
#----------------------------------------
sub GetPageOrEditLink { my ($id, $name) = @_; my (@temp, $exists, $anchor);
$id =~ s/(.*)(\#.*)/$1/; $anchor = $2; ... return &GetPageLinkText($id . $anchor, $name . $anchor); ... return $name . &GetEditLink($id,"?") . $anchor; }
#----------------------------------------
sub InitLinkPatterns { ... if ($UseSubpage) { # Loose pattern: If subpage is used, subpage may be simple name $LinkPattern = "(?:(?:$LpA)?\\/$LpB)|$LpA"; # Strict pattern: both sides must be the main LinkPattern # $LinkPattern = "(?:(?:$LpA)?\\/)?$LpA"; } else { $LinkPattern = "$LpA"; } #$AnchorPattern = "\#[\-A-Za-z0-9_:\.]+"; # browser compatible, w3c incompatible $AnchorPattern = "\#[A-Za-z][\-A-Za-z0-9_:\.]*"; # http://www.w3.org/TR/1998/REC-html40-19980424/types.html#type-id $LinkPattern = "($LinkPattern(?:$AnchorPattern)?)"; # anchorname included as an optional trailing item
$QDelim = '(?:"")?'; # Optional quote delimiter (not in output) $LinkPattern .= $QDelim; ... }
#----------------------------------------