Markup Extension writing
Hans Bracker <[email protected]> Mon, 9 Feb 2026 21:52:07 +0000
| Newsgroups | gmane.comp.web.wiki.pmwiki.user |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============7624910561867034327==
Content-Type: multipart/alternative;
boundary="------------qZYXvE2fVzTtaYcAa5VV6S7P"
Content-Language: en-GB
This is a multi-part message in MIME format.
--------------qZYXvE2fVzTtaYcAa5VV6S7P
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
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
--------------qZYXvE2fVzTtaYcAa5VV6S7P
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!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>
--------------qZYXvE2fVzTtaYcAa5VV6S7P--
--===============7624910561867034327==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
pmwiki-users mailing list
[email protected]
http://www.pmichaud.com/mailman/listinfo/pmwiki-users
--===============7624910561867034327==--