Re: Markup Extension writing

Peter Kay <[email protected]> Tue, 10 Feb 2026 09:01:49 -0500
Newsgroups gmane.comp.web.wiki.pmwiki.user
Message-ID <CADYA+TB+HVKU_-fvY6MmVooYRg8sgPhyNBhHCU88StAGAB_Gaw@mail.gmail.com>
--===============9102951931322175170==
Content-Type: multipart/alternative; boundary="000000000000efc8fa064a78b2da"

--000000000000efc8fa064a78b2da
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I seem to recall doing something like this with a recursive call. It's
obviously resource intense if you get a huge amount of traffic but works
fine. I had a rough working recipe before other parts of life took me away.
I can look for what I did if it might help.
--Peter Kay

On Tue, Feb 10, 2026, 7:20=E2=80=AFa.m. Hans Bracker <[email protected]> w=
rote:

> Yes, sum does work. The MarkupExprPlus recipe definitions of add, sub,
> mul and div don't work with 'strcount'. I can fix it and get the value,
> not the token,  by adding a line of code to top of the function, like
> this, calling MarkupRestore():
>
> function MEP_nums($params) {
>    $params =3D trim(MarkupRestore($params));
>    $params =3D preg_split('/\\s+/', $params);
>    $args =3D array();
>    foreach ($params as $p) {
>      list($d) =3D sscanf($p, "%g");
>      if (is_numeric($d)) $args[] =3D $d;
>    }
>    return $args;
> }
>
> Is there another way than rewriting recipes?
>
> Hans
>
>
> On 10/02/2026 10:44, Petko Yotov wrote:
> > This seems to work for me.
> >
> > I tried your code, and the {(sum)} expression on the Cookbook, with
> > this markup:
> >
> >   {(sum (strcount are PmWiki.BasicEditing) -6)}
> >
> > The string "are" appears 16 times in my BasicEditing.
> >
> > The result is correctly 16 - 6 =3D 10.
> >
> > Definition:
> > $MarkupExpr['sum'] =3D 'array_sum($args)';
> > $MarkupExpr['strcount'] as below.
> >
> > Petko
> >
>
> _______________________________________________
> pmwiki-users mailing list
> [email protected]
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
>

--000000000000efc8fa064a78b2da
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">I seem to recall doing something like this with a recursi=
ve call. It&#39;s obviously resource intense if you get a huge amount of tr=
affic but works fine. I had a rough working recipe before other parts of li=
fe took me away. I can look for what I did if it might help.<div dir=3D"aut=
o">--Peter Kay=C2=A0</div></div><br><div class=3D"gmail_quote gmail_quote_c=
ontainer"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Feb 10, 2026, 7:20=
=E2=80=AFa.m. Hans Bracker &lt;<a href=3D"mailto:[email protected]">design=
@softflow.uk</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin=
g-left:1ex">Yes, sum does work. The MarkupExprPlus recipe definitions of ad=
d, sub, <br>
mul and div don&#39;t work with &#39;strcount&#39;. I can fix it and get th=
e value, <br>
not the token,=C2=A0 by adding a line of code to top of the function, like =
<br>
this, calling MarkupRestore():<br>
<br>
function MEP_nums($params) {<br>
=C2=A0=C2=A0 $params =3D trim(MarkupRestore($params));<br>
=C2=A0=C2=A0 $params =3D preg_split(&#39;/\\s+/&#39;, $params);<br>
=C2=A0=C2=A0 $args =3D array();<br>
=C2=A0=C2=A0 foreach ($params as $p) {<br>
=C2=A0=C2=A0 =C2=A0 list($d) =3D sscanf($p, &quot;%g&quot;);<br>
=C2=A0=C2=A0 =C2=A0 if (is_numeric($d)) $args[] =3D $d;<br>
=C2=A0=C2=A0 }<br>
=C2=A0=C2=A0 return $args;<br>
}<br>
<br>
Is there another way than rewriting recipes?<br>
<br>
Hans<br>
<br>
<br>
On 10/02/2026 10:44, Petko Yotov wrote:<br>
&gt; This seems to work for me.<br>
&gt;<br>
&gt; I tried your code, and the {(sum)} expression on the Cookbook, with <b=
r>
&gt; this markup:<br>
&gt;<br>
&gt; =C2=A0 {(sum (strcount are PmWiki.BasicEditing) -6)}<br>
&gt;<br>
&gt; The string &quot;are&quot; appears 16 times in my BasicEditing.<br>
&gt;<br>
&gt; The result is correctly 16 - 6 =3D 10.<br>
&gt;<br>
&gt; Definition:<br>
&gt; $MarkupExpr[&#39;sum&#39;] =3D &#39;array_sum($args)&#39;;<br>
&gt; $MarkupExpr[&#39;strcount&#39;] as below.<br>
&gt;<br>
&gt; Petko<br>
&gt;<br>
<br>
_______________________________________________<br>
pmwiki-users mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank" rel=3D"noref=
errer">[email protected]</a><br>
<a href=3D"http://www.pmichaud.com/mailman/listinfo/pmwiki-users" rel=3D"no=
referrer noreferrer" target=3D"_blank">http://www.pmichaud.com/mailman/list=
info/pmwiki-users</a><br>
</blockquote></div>

--000000000000efc8fa064a78b2da--


--===============9102951931322175170==
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

--===============9102951931322175170==--