[pmwiki-devel] Question on Markup Development: How to map Markups to Markups?

Petko Yotov 5ko at 5ko.fr
Fri Mar 18 03:03:49 PDT 2022


On 18/03/2022 10:50, Jan Peters wrote:
> I want to write a macro that wraps around videoattach.php as a
> shortcut for my pmwiki users:
> 
> Markup_e('leftvideo', 'directives',
> "/\\(:leftvideo\\s+(.*?)\\s*:\\)/",
> “leftvideo(\$m[1])”);
> 
> function leftvideo($video_code) {
>         $output = "(:div class='igrid':) $video_code (:divend:)";
>         return $output;
> }

First, you should really use Markup() not Markup_e() otherwise your code 
will break with recent PHP versions:

   Markup_e('leftvideo', 'directives',
     "/\\(:leftvideo\\s+(.*?)\\s*:\\)/",
     "leftvideo");

function leftvideo($m) {
   $video_code = $m[1];
   // ...
}

> Weirdly, the “(:divend:)” is treated as text while the rest is
> processed correctly. Do you have any
> ideas how to do this properly?

If your function returns wiki markup, it can call PRR() "PmWiki Redo 
Rules" either before returning the markup, or with the return value:

   return PRR($output);

See also:

   https://www.pmwiki.org/wiki/Cookbook/Functions#PRR

And the answer after "How can the text returned by my markup function be 
re-processed by the markup engine?" in the page:

   https://www.pmwiki.org/wiki/PmWiki/CustomMarkup#PRR

Petko



More information about the pmwiki-devel mailing list