PmWiki’s markup translation engine is handled by a set of rules; each rule searches for a specific pattern in the markup text and replaces it with some replacement text. Internally, this is accomplished by using PHP’s “preg_replace” function.
Rules are added to the translation engine via PmWiki’s Markup() or function, which look like
Markup($name, $when, $pattern, $replace); # if no evaluation is needed, or if PHP < 5.5 Markup($name, $when, $pattern, $replace_function); # if evaluation is needed # DEPRECATED, will not work as of PHP 7.2 Markup_e($name, $when, $pattern, $replace); # if evaluation is needed and 5.5<=PHP<=7.1
$nameis a unique name (a string) given to the rule
$whensays when the rule should be applied relative to other rules
$patternis the pattern to be searched for in the markup text
$replaceis what the pattern should be replaced with.
$replace_functionis the name of the function which should be called with the match, and should return the replacement.
For example, here’s the code that creates the rule for
''emphasized text'' (in scripts/stdmarkup.php):
Markup("em", "inline", "/''(.*?)''/", "<em>$1</em>");
Basically this statement says to create a rule called “em” to be performed with the other “inline” markups, and the rule replaces any text inside two pairs of single quotes with the same text match not begin/end of strings but also begin/end of lines (i.e., right before/after a newline). Also make sure your markup is executed during the fulltext phase.
Q How can the text returned by my markup function be re-processed by the markup engine?
If the result of your markup contains more markup that should be processed, you have two options. First is to select a “when” argument that is processed earlier than the markup in your result. For example, if your markup may return [[links]], your “when” argument could be
“<links” and your markup will be processed before the links markup. The second option is to call the PRR() function in your markup definition or inside your markup function. In this case, after your markup is processed, PmWiki will restart all markups from the beginning.
Q How do I get started writing recipes and creating my own custom markup?
Q How do I make a rule that runs once at the end of all other rule processing?
Use this statement instead of the usual
$MarkupFrameBase[‘posteval’][‘myfooter’] = “\$out = onetimerule(\$out);”;