[pmwiki-users] Re: recipe programming special markup

Patrick R. Michaud pmichaud at pobox.com
Sat Sep 10 22:04:12 CDT 2005


On Sat, Sep 10, 2005 at 08:55:30PM +0000, Karl Loncarek wrote:
> "Patrick R. Michaud" <pmichaud at pobox.com> wrote 
> > On Sat, Sep 10, 2005 at 02:45:26PM +0000, Karl Loncarek wrote:
> >> but
> >> $out = "sometext\n"."!!!!!Header";
> >> doesn't work also.
> > 
> > This should work, so I'm guessing there must be something *else*
> > happening that is causing the problem.  
>
> OK, lets use different examples (as simple as possible):
> 
> Markup('preHeader', '<include', '/(?m:^)(!{1,6})\\s?(.*)$/', "xxxxx\n$1
> $2");
> 
> -> When I do this PHP seems to hang (or do some infinte loop).

This regexp won't ever match -- the '(.*)' won't match anything 
containing a newline, and the $ requires matching to the very 
end of the markup text.  (Since this is being done before include,
the markup text hasn't been broken into links yet -- i.e., you're
still working with the full text.)

It's "hanging" because that (.*) on the entire markup text gives 
it a huge number of possibilities to try.

Here are my suggestions -- first, I wouldn't use (?m:^) to try
to match the beginning of a line.  Just match a newline directly, 
or do a lookbehind for a newline.  Second, I don't think you need to
capture the text following the !!!'s for this.  So, something like

    Markup('preHeader', '<include',
      "/(\\n!{1,6})/",
      "xxxxx$1");

is probably what you want.

> Markup('preHeader', 'directives', '/(?m:^)(!{1,6})\\s?(.*)$/', "xxxxx\n$1
> $2");
> 
> ->This works in that way that "xxxxx" is displayed before the header. But 
> the Header is not recognized or parsed anymore with the header markup!

Yes, because "directives" takes place after the full text is
split into separate lines, so adding a newline here doesn't break
this line into multiple "lines".  The remainder of the markup rules 
see the whole thing as being a single "line", which no longer 
begins with '!!!' so it's not treated as a heading.  There *is* a 
way to tell the markup rules to go ahead and reparse the current 
string for newlines (via the PRR() function), but you really don't 
need that here.

Pm




More information about the pmwiki-users mailing list