PmWikiPlus-Talk

Summary: Talk page for PmWiki Plus.
Maintainer: simon
Users: +1 (View / Edit)

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 $MarkupExpr 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['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:

  • $params is 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)';
    $params may contain escaped values representing quoted arguments and results of other expressions; these values may be un-escaped by using
    preg_replace_callback($rpat, 'cb_expandkpv', $params).
  • $args is a simple array strings, space separated tokens from the markup expression's text string, actually this is the [''] array returned by ParseArgs(). 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)'; .
  • $argp is the output from returned by ParseArgs() 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)';
  • $pagename is the name of the PmWiki page where the markup expression was used
  • $func is the name of the markup expression, e.g. fnmrkupexpr
  • $rpat is a regular expression capture group "(\d+P)", for use with cb_expandkpv()
  • $repl is 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 {}
Function 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).

simon

Talk page for the PmWiki Plus recipe (users).