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

0 views
Skip to first unread message

Jan Peters

unread,
Mar 18, 2022, 5:51:43 AM3/18/22
to pmwiki...@pmichaud.com
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;
}

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

_______________________________________________
pmwiki-devel mailing list
pmwiki...@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-devel

Petko Yotov

unread,
Mar 18, 2022, 6:05:44 AM3/18/22
to Jan Peters, pmwiki...@pmichaud.com
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

Reply all
Reply to author
Forward
0 new messages