[pmwiki-users] Markup Extension writing

Hans Bracker design at softflow.uk
Mon Feb 9 13:52:07 PST 2026


Hi Petko, I am trying to define some Markup Extensions which can be 
embedded in other MEs for use in calculations. I just wrote one for 
counting strings. It returns a number. But when it is inside a ME like 
{(sum (strcount <needle>  HaystackPage)  10 )} to add 10 to count number 
then this fails. The sum ME does not receive the count number from ME 
strcount, but a keep token.

I can only solve this by rewriting the 'sum' ME to use $params instead 
of $argp and add to the function at the top    $p = 
ParseArgs(MarkupRestore($params));
to get the parameters without Keep token. This seems like too much code 
hacking in the wrong places. Is there a way that my strcount ME can 
return the value without it being made into a token in the ME process, 
so other MEs do not need to be hacked?

This is the new strcount markup expression:

// (strcount <needle> <HayStack>), (strcount <needle>),
//(strcount <needle> page=<HayStack>),(strcount <needle> 
pages=<Page1,Page2,Page3>)
$MarkupExpr['strcount'] = 'MxStringCount($pagename, @$argp)';
function MxStringCount($pn, $argp) {
     $find = $argp['find'] ?? $argp[''][0] ?? '';
     if ($find=='') return '';
     $pgs = $argp['pages'] ?? $argp['page'] ?? $argp[''][1] ?? $pn;
     if (strpos($pgs,',')) $pages = explode(',',$pgs);
     else $pages = array($pgs);
     $cnt = 0;
     foreach ($pages as  $p) {
         $sect = strstr($name,'#');
         $name = MakePageName($pn, $p);
         $source = $name.$sect;
         $text = RetrieveAuthSection($pn, $source);
         $cnt += substr_count($text, $find);
     }
     return  $cnt;
}

thanks! Hans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20260209/2c2e6ea4/attachment.html>


More information about the pmwiki-users mailing list