PmWikiPlus-Talk
This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.
Markup expressions are a method to do simple computations and manipulations from markup.
The generic form of a markup expression is {(muexpr ...args)}.
The expression is called with as many arguments as are required.
Creating custom Markup Expressions
Custom markup expressions may be added by extensions and recipes.
The array is used to register Markup Expressions for processing by PmWiki.
Each entry's key is the name of the Markup Expression.
Names are case sensitive.
The entry's value is the callback function to be evaluated for that expression. e.g.
$MarkupExpr
$MarkupExpr['mymrkupexpr'] = 'mymrkupexprfunc()';
When the callback function is invoked by the pmwiki.php internal function MarkupExpression() there are several local variables usable in any order as arguments:
$paramsis a simple string that contains all the text from the markup expression name to the closing brackets including leading and trailing spaces,
e.g.$MarkupExpr['myparams'] = 'fnmyparams($params)';
$paramsmay contain escaped values representing quoted arguments and results of other expressions; these values may be un-escaped by usingpreg_replace_callback($rpat, 'cb_expandkpv', $params).$argsis a simple array strings, space separated tokens from the markup expression's text string, actually this is the['']array returned byParseArgs(). Specific arguments can be used as parameters, parameters such as "key='val'" are not available.
e.g.$MarkupExpr['myargs'] = 'fnmyargs($args[0], $args[1])';or$MarkupExpr['myargs'] = 'fnmyargs($args)';.$argpis the output from returned byParseArgs()with the standard entries for %['#'], %[''], %['+'], %['-']. Specific arguments can be used as parameters,
e.g.$MarkupExpr['myargp'] = 'fnmyargp($argp['key'], $argp['ext'])';or$MarkupExpr['myargp'] = 'fnmyargp($argp)';is the name of the PmWiki page where the markup expression was used$pagename$funcis the name of the markup expression, e.g.fnmrkupexpr$rpatis a regular expression capture group "(\d+P)", for use withcb_expandkpv()$replis the entire bracketed markup, e.g. for{(mymrkupexpr p1 key='val' "q12=809##" )}is "(mymrkupexpr p1 key=val q12=809## )". Quotes are removed from arguments, spaces are retained.
For example:
mymrkupexprfunc (string $params, array $args, array $argp, string $pagename, string $rpat, string $repl):string {}
cb_expandkpv() is defined in pmwiki.php and restores kept/protected strings.
I recently updated the suggestions in the header of markupexpr.php, but indeed additional documentation will be appropriate -- with the new interface with a callback from PmWiki 2.7. (Maybe on another cookbook or talk page though, easier for people to find.) --Petko
I'm thinking this could become PmWiki.CustomeMarkupExpressions, like PmWiki.CustomMarkup.I wrote this because I needed more details on the arguments that can be passed.
I'm updating this from markupexpr.php (which I didn't think of looking in).
Talk page for the PmWiki Plus recipe (users).