[pmwiki-users] custom sourceblock markup

Alexandre Leray alexandre at stdin.fr
Thu Feb 10 16:44:49 CST 2011

Thanks a lot Peter!

here is the recipe for those interested (I did not include the class arg

// Creates a code block marker
Markup("highlight", ">markupend",
"/\\(:highlight:\\)\\n(.*?)\\(:highlightend:\\)/es", "do_highlight('$1')");

function do_highlight($content) {
    $new_content = '<pre><code>';
    $new_content .= Keep(PSS($content));
    $new_content .= '</code></pre>';
    return $new_content;

I'm not sure about the ">markupend" argument, but it seems to work so
far. Note the PSS() function call in do_highlight(); It is used to
"removes the backslashes that are automatically inserted in front of
quotation marks by the /e option of PHP's preg_replace function"[^1].

[^1]: http://www.pmwiki.org/wiki/PmWiki/Functions

Kind regards,


On 10/02/11 19:22, Peter Bowers wrote:
> On Thu, Feb 10, 2011 at 7:01 PM, Alexandre Leray <alexandre at stdin.fr> wrote:
>> Here is what I have so far (without the class="lang" implemented yet):
>> Markup("highlight", "fulltext",
>> "/\\(:highlight:\\)(.*?)\\(:highlightend:\\)/s",
>> "<pre><code>$1</code></pre>");
>> The problem is that pmwiki processes the inner content of the block
> Keep() is the key you're looking for -- it's an ingenious method for
> preventing any other markup rules from operating over the text that
> has been "kept".  Try something like this:
>> Markup("highlight", "fulltext",
>> "/\\(:highlight:\s*(.*?)\\)(.*?)\\(:highlightend:\\)/s",
>> keep("<pre><code class=\"$1\">$2</code></pre>"));
> You might look at these pages for more help:
> * http://www.pmwiki.org/wiki/PmWiki/CustomMarkupAlt
> * http://www.pmwiki.org/wiki/PmWiki/CustomMarkup
> -Peter

More information about the pmwiki-users mailing list