[pmwiki-users] nested span tag markup

Petko Yotov 5ko at 5ko.fr
Fri Oct 18 15:30:24 CDT 2013

jens at quefaire.de writes:
> I'm trying to write a markup rule for nested span tags.
> Example:
> (:span SomeAttr="x":)Text
> (:span1 someAttr="y":)nested span
> (:span1end:)some more text in outer span
> (:spanend:)
> should result in
> <span SomeAttr="x">Text<span someAttr="y">nested span</span>some more text  
> in outer span</span>
> I grabbed the code from an old post in this list concerning nested block  
> elements. After playing around with the regexp, it will sometimes generate  
> correct html, but often pmwiki will incorrectly add '</p>' or something  
> else, to close the block.
> Currently the rule is inserted before any block markup rule ('<block'). What  
> is the correct position in the markup list for this kind of markup? Is there  
> a way to prevent pmwiki from inserting additional block element tags?

The <span> tag is an inline HTML tag so it may be better to place it with  
other 'inline' rules (instead of '<block' use 'inline').

BTW the block function you use is somewhat complex because we want it  
automatically to close previously opened tags of the same level. If you  
don't mind manually closing every open tag, there may be a much simpler  
markup rule:

  Markup('span', 'inline', '/\\(:span +(\\s?.*?):\\)/ie',
    '"<span ".PQA(PSS("$1")).">"');
  Markup('spanend', 'inline', '/\\(:span(end)?:\\)/i', '</span>');

Then in a wiki page, use
  (:span title="this is a tooltip" style="color:red;":)red text(:span:)
  (:span title="Tooltip":)some (:span style="color:red;":)red(:span:) text(:span:)

I have here (:span:) with no arguments the same as (:spanend:).

Just note that if you don't close every open <span> tag, your page may have  
non-standard output. Also note that an open <span> tag must be closed with  
</span> inside the same block tag (<div>, <p>, <td> etc.) for the output to  
be valid.

> Here's the code (file nestspan.php):
> <?php if (!defined('PmWiki')) exit();
> function HTMLBlock($block, $name, $attr) {
>   global $MarkupFrame;
>   $attr = PQA($attr);
>   $name = strtolower($name);
>   $key = preg_replace('/end$/', '', $name);
>   $out = '<:block>'.MarkupClose($key);
>   if (substr($name, -3) == 'end') return $out;
>   $cf = & $MarkupFrame[0]['closeall'];
>   $out .= "<$block $attr>";
>   $cf[$key] = "</$block>";
>   return $out;
> }
> Markup('nestspan', '<block',
>   '/\\(:(span([^\\s]*(end)?))(\\s?.*?):\\)/ie',
>   "HTMLBlock('span','$1',PSS('$4'))");
> ?>
> regards
> Jens
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users

More information about the pmwiki-users mailing list