[pmwiki-users] Markup() Abuse Recommendations.

Stirling Westrup sti at pooq.com
Mon Oct 23 12:55:34 CDT 2006


Patrick R. Michaud wrote:
> On Sun, Oct 22, 2006 at 08:11:25PM -0400, Stirling Westrup wrote:
>> I have an array of regex keys and their corresponding replacements. I
>> can easily imagine it growing to several hundred entries. I need to
>> enter each of these into the Markup() function while ensuring that they
>> are executed in the order they are given.  Now, I can imagine doing
>> something like this:
>>
>> $i = 0;
>> $last = inline;
>> $base = 'MyName:';
>> foreach($patterns as $pat => $rep)
>>   { $name = $base.$i++;
>>
>>     Markup($last,$name,$pat,$rep);
>>     $last = ">$name";
>>   }
>>
>> The question is: is this the best way? 
> 
> I don't have a better one off the top of my head.

Okay. Then that's what I'll go with.

> One thing you could try is to do something similar to the
> way the InterMap code works, which combines all of the keys into
> a single pattern to be matched.  For example:
> 
>     Markup('acronym', 'inline',
>       '/\\b(html|xml|http|tcpip|dhcp|smtp|pop)\\b/e',
>       "Acronym(PSS('$1'))");
> 

That was my initial attempt. Alas there is no reliable way to know which
alternative matched when there are zero-length assertions involved. I
actually found that one of my test cases needed something like this:

Markup
  ( 'acronym', 'directives'
  , '/((?:[^\n](?=<p))|(?:[^\n](?=\n<p)))/m'
  ,"Replacement(PSS('$1'))"
  );

Where $1 ends up having the same contents for two different branches of
the regex, but the replacements are different. The method of multiple
Markup calls is clumsier, but handles that case, so I guess that's how
I'll do it.




More information about the pmwiki-users mailing list