[Pmwiki-users] multiline markup

Patrick R. Michaud pmichaud
Sat Jan 8 13:04:34 CST 2005


On Fri, Jan 07, 2005 at 01:14:49PM -0500, pmwikiuser at estrider.com wrote:
> 
> I\'m trying to create a markup that will handle multiple lines (strings
> with newline characters),  but I\'ve been running into problems with
> regex matching.  My problem is that (.*?) will not match \\n and the
> ways I know to get around it don\'t seem to work in the context of a
> Markup() statement. 

There's several factors at work here.  First, the normal way to get (.*?) 
to match newlines is to add the /s option to the end of the pattern, 
as in "/abcd(.*?)efg/se" .

Then, it's important to note that one of PmWiki's markup rules splits
the texts into separate lines to be able to do line-by-line processing
of the contents (as well as for performance reasons).  Thus, if you 
want to match things with newlines in them, you have to do one of the
following:
   1. Set your markup to occur sometime before the 'split' transformation --
      i.e., within the "fulltext" section.  The (:if:)/(:ifend:)
      markups do this.
   2. Capture the target of the the markup containing the newlines
      inside of a [=...=] or [@...@] section.  The (:markup:) and
      Cookbook.Beautifier give examples of doing this.
   3. Treat the begin/end markups as separate rules and maintain the
      state in global variables.  The (:table:), (:cell:), and (:tableend:)
      markups operate this way.

> Any suggestions on how to make:
>     (:BOB:) some
>     multi line
>     text
>     (:BOBEND:)
> become 
>     <span id=\'BOB\'>some
>     multi line
>     text
>     </span>

You probably want to use <div> instead of <span> here, because 
<span> cannot contain other block markup (<p>, <ul>, <li>, etc.) and
each of the things inside of the BOB/BOBEND will generate some sort of
block markup.  Also, remember that if you use id="..." then there
can only be one such BOB/BOBEND sequence in a page (HTML requires
id attributes to be unique).

That said, this looks a lot like the (:table:) markup, so you might look
at that for some ideas (in scripts/stdmarkup.php).  This also reminds me
that I still need to implement (:div:).  When I do that (for 2.0.beta15), 
would this work for you...?

   (:div id='BOB') some
   multi
   line
   text
   (:divend:)

generating

   <div id='bob'> some
   multi
   line
   text
   </div>

Of course, you could then easily alias (:BOB:)/(:BOBEND:) to the 
appropriate (:div id='BOB':) and (:divend:) markups.  And if you're
really intending this to be sections for different authors, we could
even write a Cookbook so that the end tags are automatically generated,
and the following would work:

   BOB> some multi
   line text (including lists, pre, etc.) rendered with
   Bob's settings inside of a <div class='BOB'>

   ALICE> closes Bob's section, starts
   new text rendered with
   Alice's settings inside of a <div class='ALICE'>

   BOB>  Another section of responses 
   and comments for Bob

   >  this ends whatever section was last open and returns to "normal"
   text

Although if we do something like this we should probably integrate it
with WikiStyles somehow (not difficult).

Pm 



More information about the pmwiki-users mailing list