<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p><font size="2">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. </font></p>
<p><font size="2">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));<br>
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?</font></p>
<p><font size="2">This is the new strcount markup expression:</font></p>
<p><font size="2">// (strcount <needle> <HayStack>),
(strcount <needle>), <br>
//(strcount <needle> page=<HayStack>),(strcount
<needle> pages=<Page1,Page2,Page3>) <br>
$MarkupExpr['strcount'] = 'MxStringCount($pagename, @$argp)';<br>
function MxStringCount($pn, $argp) {<br>
$find = $argp['find'] ?? $argp[''][0] ?? '';<br>
if ($find=='') return '';<br>
$pgs = $argp['pages'] ?? $argp['page'] ?? $argp[''][1] ??
$pn;<br>
if (strpos($pgs,',')) $pages = explode(',',$pgs); <br>
else $pages = array($pgs);<br>
$cnt = 0;<br>
foreach ($pages as $p) { <br>
$sect = strstr($name,'#'); <br>
$name = MakePageName($pn, $p); <br>
$source = $name.$sect;<br>
$text = RetrieveAuthSection($pn, $source);<br>
$cnt += substr_count($text, $find);<br>
}<br>
return $cnt;<br>
}</font></p>
thanks! Hans
</body>
</html>