[pmwiki-devel] How does [= =] work in PmWiki...

The Editor editor at fast.st
Mon Dec 4 22:29:16 CST 2006


Can someone explain how PmWiki "Keeps" markup from being processed?
I've been studying the code below (from stdmarkup.php) but it doesn't
make much sense to me.  I have some markup I'd like to protect from
later markup if it's so tagged.  IE,

(:markup1:)text text (:nomarkup1:)more text(:endnomarkup1:)text text
(:endmarkup1:)

It's not possible in this case to do a simple reversal of the markup
change. And there might be multiple instances on a page... I can get
the patterns now matching pretty well but this is a perplexer.

Here's a stab at a plan: you somehow store each protected section as
an array element, and temporarily replace it with some kind of token
id'd to that array key. Then after the other processing is complete
you replace the tokens with the appropriate array element.  Is this at
all going down the right road?

Cheers,
Caveman





PM's code:

function PreserveText($sigil, $text, $lead) {
  if ($sigil=='=') return $lead.Keep($text);
  if (strpos($text, "\n")===false)
    return "$lead<code class='escaped'>".Keep($text)."</code>";
  $text = preg_replace("/\n[^\\S\n]+$/", "\n", $text);
  if ($lead == "" || $lead == "\n")
    return "$lead<pre class='escaped'>".Keep($text)."</pre>";
  return "$lead<:pre,1>".Keep($text);
}

Markup('[=','_begin',"/(\n[^\\S\n]*)?\\[([=@])(.*?)\\2\\]/se",
    "PreserveText('$2', PSS('$3'), '$1')");
Markup('restore','<_end',"/$KeepToken(\\d.*?)$KeepToken/e",
    '$GLOBALS[\'KPV\'][\'$1\']');
Markup('<:', '>restore',
  '/<:[^>]*>/', '');



More information about the pmwiki-devel mailing list