[Pmwiki-users] tree-syntax alternative
J. Meijer
commentgg
Sun Aug 1 18:29:26 CDT 2004
As an alternative to a fully integrated tree syntax, for experimenting, the code below implements this syntax:
[linktext -> link]
The ': linktext' part is optional and replaces the default linktext (just the pagename). Link can be like these formats (current page is assumed to be 'Top.Middle.Group.Page'):
[-> PeerPage] Top.Middle.Group.PeerPage (peer reference)
[-> PeerGroup.PeerPage] Top.Middle.PeerGroup.PeerPage
[-> PeerPage/SubPage] Top.Middle.Group.PeerPage.SubPage
[-> /SubPage] to subpage of current page
[-> //Top.Middle.Group] Top.Middle.Group (global reference)
[-> .Middle] Top.Middle (anchored reference)
[click here -> PeerPage/SubPage] displays as 'click here'
Mild warning: pmwiki.php must be patched (see code). The patch causes all multi-level wikilinks to be recognized, allowed and resolved by pmwiki. Unless the link is a bare WikiWord, they will reference global links.
I used [-> to start the construct, but I preferred [=>. This is not possible because [=..=] takes precedence.
For play.
jan
#-code---------------------------------------------
# enable [linktext -> treelink] syntax
# put in the local/config.php at the end
# because $GroupNamePattern is replaced.
function resolveTreeLink($lnk,$pg) {
# static $cnt;if($cnt > 20) return'';
# print"<br/>Link '$lnk' in '$pg' ";
$lnk=trim($lnk);
if(false!==$i=strpos($lnk,'/')) { # PeerPage/SubPage OR //PmWiki.Documentation
if(($i==0) and (@$lnk[1]=='/')) return substr($link,2);
$lnk=explode('/',$lnk,2);
if(!$i) return "$pg.$lnk[1]";
return resolveTreeLink($lnk[0],$pg).'.'.$lnk[1];
} else { #normal relative or anchored link (.Middle.Page)
$lnks=explode('.',$lnk);
$pg=explode('.',$pg);
if($lnk[0]!='.') { # peer page
$pg=array_splice($pg,0,count($pg)-count($lnks));
if($pg=implode($pg,'.'))$pg.='.';
return $pg.$lnk;
} else { # anchored .Middle.Page
while(count($pg) and (array_pop($pg)!=$lnks[1]));
if(!$pg=implode('.',$pg)) return substr($lnk,1);
return $pg.$lnk;
}
}
}
function PrintTreeLink($lnk,$txt) {
global $pagename;
if(!$txt) {
if(($i=strrpos($lnk,'.')) < ($j=strrpos($lnk,'/'))) $i=$j;
$txt=$lnk;
if($i) $txt=substr($txt,$i+1);
}
print '<a href="'.resolveTreeLink($lnk,$pagename)."\">$txt</a>";
}
# enable [latest -> PmWiki.V108.FmtWikiLink] syntax
$DoubleBrackets['/\\[(?:(.+?))? ?-> ?(.*?)\\]/e']='PrintTreeLink("$2","$1")';
# enable [[latest -> PmWiki.V108.FmtWikiLink]] syntax (alternative)
#$DoubleBrackets['/\\[\\[(?:(.+?))? ?-> ?(.*?)\\]\\]/e']='PrintTreeLink("$2","$1")';
$OLDGNP=$GroupNamePattern;
$GroupNamePattern="{$OLDGNP}(?:[\\/.]$OLDGNP)*";
### You need to PATCH pmwiki.php: ###
#--- if (preg_match("/^($GroupnamePattern)[\\/.]?\$/",$pagename,$match)) {
#+++ if (preg_match("/^($OLDGNP)[\\/.]?\$/",$pagename,$match)) {
# goodluck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-users_pmichaud.com/attachments/20040801/2ce5800a/attachment.htm
More information about the pmwiki-users
mailing list