[pmwiki-users] automatic link creation
adam overton
a at plus1plus1plus.org
Wed Aug 26 22:24:30 CDT 2009
hi
so here some of my personal conclusions from everyone's wonderful
emails.
* InterMap
i couldn't figure out how to make InterMap work for my situation. if
i'm correct, it seems InterMap is looking for something like -
AnotherSite:OneOfItsPages - and i'm looking for something that
replaces text that has no idea that one day it will be a link. i.e.
so that John Doe becomes [[http://johndoe.com|John Doe]] without any
forethought or link markup written.
but perhaps i'm misunderstanding how the InterMap could be
implemented. the thing that is so nice about the InterMap setup is
that you can maintain your list on a wiki page, instead of in
config.php. do let me know if i'm missing something here...
* Markup
i mangled PM's code (similar to Peter's - thanks!) a bit and got the
following case-insenstive version to work deliciously. it also
includes Eemeli's great idea of having a back-tick escape figure so
that:
john doe turns into [[http://johndoe.com|john doe]]
John Doe turns into [[http://johndoe.com|John Doe]]
`John Doe remains John Doe
# all keys must be completely lowercase in order for this to work
$NameToLinkArray = array(
'john doe' => 'http://www.johndoe.com',
'sally struthers' => 'http://www.def.com'
);
Markup('names', 'inline',
'/(`?)\b(' . join('|', array_keys($NameToLinkArray)) . ')\b/ei',
'AutoNameToLinkFunc("$2","$1")'
);
function AutoNameToLinkFunc($name, $escape) {
global $NameToLinkArray;
if ($escape) return $name;
$link = '%newwin%[['.$NameToLinkArray[strtolower($name)].'|'.Keep
($name).']]';
return $link;
}
* i had to substitute the AutoNameToLinkFunc because i couldn't
figure out how to get pmwiki to find $NameToLinkArray - i got errors,
and had to resort to calling it as a global in a function. perhaps
someone knows how to finagle this without having to declare a
separate function, as PM did in his recent example?
question/next step:
is there a way to set up my list of names on a wiki page (like
Site.NamesToLinks), like InterMap is setup?
i like this a lot - superuseful!
i've added a page for this latter recipe: http://www.pmwiki.org/wiki/
Cookbook/AutoLink
(suggestions for a better name? this was the first that came to mind)
thanks for the help!
adam
On 26 Aug 2009, at 7:47 AM, Patrick R. Michaud wrote:
> On Wed, Aug 26, 2009 at 02:51:02AM +0200, Melodye Bowers wrote:
>> $foo = array('John' => 'http://www.abc.com', 'Sally' => 'http://
>> www.def.com');
>> foreach ($foo as $name => $site) {
>> Markup('/\b'.$name.'\b/', '%newwin%'.$site.'%%', ...);
>> }
>>
>> Does that work?
>
> It "works", but only for very small numbers of names. After adding
> 100 or so such rules the speed of markup processing will degrade
> noticeably.
>
> Better would be to combine all of the names into a single markup rule
> (code below is untested, for illustration only):
>
> $foo = array('John' => 'http://www.abc.com',
> 'Sally' => 'http://www.def.com');
>
> Markup('names', 'inline',
> '/\b(' . join('|', array_keys($foo)) . ')\b/e',
> "'[['.\$foo[$1].'|'.Keep('$1').']]'");
>
> It's also possible that one could make use of the $IMap array
> for this in config.php (also untested):
>
> $IMap['John'] = 'http://www.abc.com/';
> $IMap['Sally'] = 'http://www.def.com/';
>
> Pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20090826/d19bcf3c/attachment-0001.html
More information about the pmwiki-users
mailing list