|
Cookbook /
MarkupExprPlusSummary: Extends {(...)} expression markups
Version: 2010-09-01
Prerequisites: pmwiki 2.1.27 to 2.2.x and eventually MarkupExpressions
Status: Beta
Maintainer: Dfaure
Download: markupexprplus.phpΔ
Questions answered by this recipeMarkupExpressions is cool for simple operations, but how could I handle more complex expressions involving: arithmetic operations, conditionnal values, regular expressions,... ? DescriptionThe markupexprplus.phpΔ script expands the original MarkupExpressions recipe (core built-in since version 2.2.0-beta43) essentially by enabling *real* expression nesting (ie. able to handle arithmetic operations). It also defines various extra functions ranging from basic math to advanced string manipulation. The operations defined by this recipe include add, sub, mul, div, mod, rev, rot13, urlencode, urldecode, reg_replace, sprintf, wikiword, test, and if. The recipe also provides some configuration flags applying deeper modifications to the original script behavior such as multiline expressions handling and variable manipulation. add, sub, mul, div, mod"add", "sub", "mul", "div" and "mod" expressions handle their arguments as numeric data and compute the resulting value.
rev, rot13"rev" and "rot13" expressions transform strings by respectively reversing it and applying the ROT13 encoding on it. The ROT13 encoding simply shifts every letter by 13 places in the alphabet while leaving non-alpha characters untouched. Encoding and decoding are done by the same function, passing an encoded string as argument will return the original version.
urlencode, urldecode"urlencode" and "urldecode" expressions allow back and forth transformation of a string in which all non-alphanumeric characters except
reg_replace , sprintf"reg_replace" and "sprintf" are wrappers around PHP's preg_replace and sprintf functions to perform regular-expressions search & replace, and string formatting.
wikiword, nomarkupThe "wikiword" expression generates wiki words according to core configuration.
The "nomarkup" expression keeps only the text resulting from a regular markup expression.
test, ifThe "test" expression evaluates arguments as a regular PmWiki condition, returning "0" or "1" accordingly.
The "if" expression outputs its 2nd or 3rd argument according to the value of the 1st one.
Portability enhancementsDixit PHP documentation: Not all conversion specifiers may be supported by your C library, in which case they will not be supported by PHP's strftime(). Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. T, D (there might be more) and dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems.
The recipe patches the "ftime" expression to enables some of the format specifier missing on Win32 platforms. Modified behavior / Configuration flags
NotesThe working considerations already expressed for MarkupExpressions apply here also. ContributorsSee Also
Release Notes
CommentsSee Discussion at MarkupExprPlus-Talk
User notes? : If you use, used or reviewed this recipe, you can add your name. The following format is recognized:
* (+) Optional positive comment. Name, date * (-) Optional negative comment. Name, date These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |