[pmwiki-users] MarkupExpressionsExtensions

Dominique Faure dominique.faure at gmail.com
Tue Apr 17 08:30:13 CDT 2007


On 4/17/07, Hans <design5 at softflow.co.uk> wrote:
> Tuesday, April 17, 2007, 11:18:57 AM, Petko wrote:
>
> > No, PHP math functions cannot be used (such as round(), sqrt(), abs(), etc.).
> > Yes, just the simplest of arithmetic -- addition, substraction,
> > multiplication, division -- and the expression *must* be written correctly.
>
> Maybe it better be called {(calculate ..)} or ({calc ... )}
> if that is what it does, and not evaluate equations with math
> functions.
>
>

I'm in fact about to release my own version of MarkupExpressions
(initially named WikiFormula), but Patrick did its own version faster
than me ;)
I've now to refactor it a bit to make it compatible with Patrick's one.

Currently, i'm able to handle expressions like below (syntax still not updated):

(:markup caption='arithmetic':) [=
* ((4+5)*(4+4)-9)/20 = {(div (sub (mul (add 4 5) (add 4 4)) 9) 20)}
* (-4) + (-5) = {(add -4 -5)}
=]

(:markup caption='string manipulation':) [=
* {(substr 'abcdef')}
* {(substr 'abcdef'  1)} &rarr; bcdef
* {(substr 'abcdef'  1 3)} &rarr; bcd
* {(substr 'abcdef'  0 4)} &rarr; abcd
* {(substr 'abcdef'  0 8)} &rarr; abcdef
* {(substr 'abcdef' -1 1)} &rarr; f
=]

(:markup caption='more strings and variables':) [=
* {((toupper (substr "{$AuthId}" 0 1))(tolower (substr "{$AuthId}" 1))-Stuff)}
* Initial value was {(set v 123)}, and now is set to {(setq v (add
{$v} 1))} {$v}
=]

(:markup caption='variables and dates':) [=
* start: {(setq start (time "12:30"))} {$start} {(ftime '%T' {$start})}
* end: {(setq end (time "13:00"))} {$end} {(ftime '%T' {$end})}
* diff: {(set diff (sub {$end} {$start}))} / {(div {$diff} 60)} /
{(gmftime '%T' {$diff})}
=]

Dom



More information about the pmwiki-users mailing list