[pmwiki-users] remove markup rules for just one run of MarkupToHTML

Carlos AB cabsec.pmwiki at gmail.com
Thu Mar 25 22:36:55 CDT 2010

On 3/25/10, Peter Bowers <pbowers at pobox.com> wrote:
> On Wed, Mar 24, 2010 at 8:29 PM, Carlos AB <cabsec.pmwiki at gmail.com> wrote:
>> I'm trying to make MarkupToHTML() put html inside a textarea, the
>> problem is that I need (:if:), (:pagelist:), and some other markups to
>> be changed for just one run and not subsequent runs.
>> I tried DisableMarkup() but it changes the markup for all  runs of
>> MarkupToHTML()  and it won't process (:if:) in Site.PageActions ,
>> *.GroupHeader|Footer pages and others.
>> How can I disable certain Markups for just one run of MarkupToHTML?
> The building of the table of markup rules and the ordering of that
> table and etc is the heart, the genius behind pmwiki.  It is
> incredibly powerful and very flexible ... to a point.  I am not aware
> of any way to do what you are looking for.
> However, maybe you could look at it differently.  If there are a
> certain subset of rules that you need to apply then the toolbox recipe
> http://www.pmwiki.org/wiki/Cookbook/Toolbox
> offers the function RunMarkupRules() which allows you to create your
> own mini-table of rules and run those rules over some markup text.
> For instance, in a recipe I often want to allow comments and
> conditional processing and include capabilities on pages -- so I just
> run those 3 rules over my page before I start using the text -- that
> greatly enhances the functionality & flexibility of a recipe...
> But if you are looking for the full set of rules or even a large
> majority of them it probably isn't too practical to build the whole
> rule table -- although I suppose ultimately it's not that big a
> deal...  Theoretically there's probalby some array in pmwiki you could
> traverse to build this array and leave something out as well -- I've
> just never looked into that particular capability...
> -Peter

Thank you for your reply Peter,

I tried some other things before your e-mail arrived, including
creating a MyMarkupToHTML function, disabling markups before running
the real MarkupToHTML and trying to re-enable it after, but it didn't
work quite well.

Finally I decided to go with something a little bit more classy and
ended up with a new BuildMarkupRules function which is now called
(take a wild guess here) MyBuildMarkupRules. :)

and it goes like this:

function MyBuildMarkupRules($rid) {
  global $MarkupTable,$LinkPattern;

  $mt = $MarkupTable;
  foreach($mt as $id=>$m){
      if (@$m['pat'] && @$m['seq']){
  return $mr;

and changed a MyMarkupToHTML accordingly to :

function MyMarkupToHTML($pagename, $text, $opt = NULL,$rid) {
  # convert wiki markup text to HTML output
  global $MarkupFrame, $MarkupFrameBase, $RedoMarkupLine;

  array_unshift($MarkupFrame, array_merge($MarkupFrameBase, (array)$opt));
  $markrules = MyBuildMarkupRules($rid);
  foreach((array)$text as $l)
    $lines[] = $MarkupFrame[0]['escape'] ? PVSE($l) : $l;
  $lines[] = '(:closeall:)';
  $out = '';
  while (count($lines)>0) {
    $x = array_shift($lines);
    foreach($markrules as $p=>$r) {
      if ($p{0} == '/') $x=preg_replace($p,$r,$x);
      elseif (strstr($x,$p)!==false) $x=eval($r);
      if (isset($php_errormsg))
        { echo "ERROR: pat=$p $php_errormsg"; unset($php_errormsg); }
      if ($RedoMarkupLine) { $lines=array_merge((array)$x,$lines); continue 2; }
    if ($x>'') $out .= "$x\n";
  foreach((array)(@$MarkupFrame[0]['posteval']) as $v) eval($v);
  return $out;

It is working fine, so far.

Thank you for speedy reply,


More information about the pmwiki-users mailing list