Re: Markup Extension writing - DFaure

Peter Kay <[email protected]> Tue, 10 Feb 2026 12:28:14 -0500
Newsgroups gmane.comp.web.wiki.pmwiki.user
Message-ID <CADYA+TAk5otZbhHpkncGU=vUJarEu5ERJ2GAa_NQtrBJ8d9ziw@mail.gmail.com>
--===============3821009311217264539==
Content-Type: multipart/alternative; boundary="0000000000003d2d34064a7b95d8"

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

It is much safer to avoid eval() if you can get around it

On Tue, Feb 10, 2026, 10:15=E2=80=AFa.m. Hans Bracker <[email protected]> =
wrote:

> I am using the latest MarkupExprPlus.
>
> Trying to write well behaving markup expressions I've now learned this:
>
> 1. My strcount Mx is okay (don't know if it is good), but the result is
> in a keep token.
> 2. For a calculating Mx I need to avoid using $params and avoid using
> $argp, because both times the value is not getting in, but only the
> token string.
> 3. Using $args is okay and the value from an embedded strcount Mx is
> getting processed.
>
> An example for a working multiplication Mx, which can take a multiple of
> args:
>
> // (multi num1 num2 ...) for multiplying numbers
> $MarkupExpr['multi'] =3D 'ME_Multi($args)';
> function ME_Multi($args) {
>    $a =3D array();
>    foreach ($args as $i =3D> $v)
>        $a[$i] =3D floatval($v);
>    $x =3D 1;
>    foreach ($a as $i =3D> $v)
>        $x =3D $x * $v;
>    return $x;
> }
>
> 4. This does not use PHP eval(). Many other calc Mxs do. I imagine it is
> better to avoid eval() (?)
>
> 5. To work with numbers  which use decimal comma instead of dot, this
> needs to  be rewritten to remove thousands dots and convert commas to
> dots. But that is a different topic!
>
> Hans
>
> On 10/02/2026 13:18, Petko Yotov wrote:
> > On 10/02/2026 13:18, Hans Bracker wrote:
> >> Is there another way than rewriting recipes?
> >
> > I don't know.
> >
> > MarkupExprPlus seems to disable the core markup expressions and add
> > its own full replacement.
> >
> > It processes not only add/sub/mul/div but all core markup expressions,
> > and any custom ones you may add.
> >
> > See if the problem appears with the latest version of MX+, and maybe
> > DFaure can reply better than me.
> >
> > Petko
> >
>
> _______________________________________________
> pmwiki-users mailing list
> [email protected]
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
>

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

<div dir=3D"auto">It is much safer to avoid eval() if you can get around it=
</div><br><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr"=
 class=3D"gmail_attr">On Tue, Feb 10, 2026, 10:15=E2=80=AFa.m. Hans Bracker=
 &lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wrote=
:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.=
8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I am using the=
 latest MarkupExprPlus.<br>
<br>
Trying to write well behaving markup expressions I&#39;ve now learned this:=
<br>
<br>
1. My strcount Mx is okay (don&#39;t know if it is good), but the result is=
 <br>
in a keep token.<br>
2. For a calculating Mx I need to avoid using $params and avoid using <br>
$argp, because both times the value is not getting in, but only the <br>
token string.<br>
3. Using $args is okay and the value from an embedded strcount Mx is <br>
getting processed.<br>
<br>
An example for a working multiplication Mx, which can take a multiple of <b=
r>
args:<br>
<br>
// (multi num1 num2 ...) for multiplying numbers<br>
$MarkupExpr[&#39;multi&#39;] =3D &#39;ME_Multi($args)&#39;;<br>
function ME_Multi($args) {<br>
=C2=A0=C2=A0 $a =3D array();<br>
=C2=A0=C2=A0 foreach ($args as $i =3D&gt; $v)<br>
=C2=A0=C2=A0 =C2=A0 =C2=A0 $a[$i] =3D floatval($v);<br>
=C2=A0=C2=A0 $x =3D 1;<br>
=C2=A0=C2=A0 foreach ($a as $i =3D&gt; $v)<br>
=C2=A0=C2=A0 =C2=A0 =C2=A0 $x =3D $x * $v;<br>
=C2=A0=C2=A0 return $x;<br>
}<br>
<br>
4. This does not use PHP eval(). Many other calc Mxs do. I imagine it is <b=
r>
better to avoid eval() (?)<br>
<br>
5. To work with numbers=C2=A0 which use decimal comma instead of dot, this =
<br>
needs to=C2=A0 be rewritten to remove thousands dots and convert commas to =
<br>
dots. But that is a different topic!<br>
<br>
Hans<br>
<br>
On 10/02/2026 13:18, Petko Yotov wrote:<br>
&gt; On 10/02/2026 13:18, Hans Bracker wrote:<br>
&gt;&gt; Is there another way than rewriting recipes?<br>
&gt;<br>
&gt; I don&#39;t know.<br>
&gt;<br>
&gt; MarkupExprPlus seems to disable the core markup expressions and add <b=
r>
&gt; its own full replacement.<br>
&gt;<br>
&gt; It processes not only add/sub/mul/div but all core markup expressions,=
 <br>
&gt; and any custom ones you may add.<br>
&gt;<br>
&gt; See if the problem appears with the latest version of MX+, and maybe <=
br>
&gt; DFaure can reply better than me.<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>

--0000000000003d2d34064a7b95d8--


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

--===============3821009311217264539==--