|
Cookbook /
MarkupExprPlusSummary: Extends {(...)} expression markups
Version: 2008-06-18
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 AlsoRelease Notes
CommentsAlong with the rev and rot13 functions an md5 function could be useful. Maybe keep it in mind for a future version of the recipe.
Blues September 18, 2007, at 04:29 AM
Is there a reason these expressions are called through a separate markup function rather than through the built-in $MarkupExpr array? I'd like to be able to use one or two of these without having to install the whole recipe. BenStallings The "separate markup function" is only a drop-in replacement of the original one defined in the core which hasn't been tailored to handle complex expressions. Feel free to "extract" the expressions token definitions you need and make your own (sub)recipe with them --Dfaure March 03, 2008, at 03:35 PM hi, is it possible to cut a Variable by String? for example: My Pagename "$Name" is Word1Word3. Now I´m searching for a solution to cut the variable infront of the String "Word3". My Problem - the Variable "$Name" can changed to "Word200"..., but the string "Word3" is set. Hope you can help me. Hendrik June 17, 2008, at 07:23 AM This is a perfect job for a regular-expressions replacement such as:
Dfaure, Could you add a mathematical operator to determine if a number is even or odd? It appears to be a simple PHP operation, but I'm no PHP programmer! I'm trying to create a Pagelist template with alternating (Zebra) background colors. The Pagelist variable, {$$PageCount}, already provides the iteration number. If an even/odd boolean function existed, then conditional markup could be used to alternate the colors. --CRAjr July 17, 2008, at 8:37 AM Have you looked at FormattingTables? The method for zebra tables works with simple table markup, even if you use it in a pagelist template. HansB
The function already exists, "mod" (modulo, reminder). You can use {(mod {$$PageCount} 2)} to print alternatively "0" or "1", {(mod {$$PageCount} 3)} to print "0", "1" or "2" etc. --Petko
Excellent! You guys are the best! Hans, I have successfully created zebra tables in the past, and that's what I first attempted. But, I was unable to get it to work in a pagelist. I'll have to go back and try again. Meanwhile, Petko, your solution works perfectly. -- CRAjr
|