00887: Ability to nest WikiStyle blocks.

Summary: Ability to nest WikiStyle blocks.
Created: 2007-02-14 13:40
Status: Awaiting feedback
Category: CoreCandidate
From: Feral
Assigned:
Priority: 3
Version: 2.2.0-beta31
OS: WinXP-sp2/Microsoft-IIS-5.1/PHPv5.0.4

Description:

Note: (2007-04-11) Votes for various options related to this proposal are now being taken at VoteOnNestedDivMarkup -- please cast a vote there!

This is meant to illustrate how to allow nesting of WikiStyle blocks, something I have often needed/wanted and feel should be a part of the core as it's use is not specific to any task, but in my opinion useful in many.

Our 'Proof'

(:div1 style="color:black; background-color:red;":)
Some text, black on red.
(:div2 style="color:silver; background-color:blue;":)
A nested div, silver on blue.
(:div2end:)
Back to our black on red div.
(:div1end:)

Some text, black on red.

A nested div, silver on blue.

Back to our black on red div.

Proposed markup:

1>>color=black bgcolor=red<<
Some text, black on red.
2>>color=silver bgcolor=blue<<
A nested div via @@>><<@@ style that is silver on blue.
2>><<
Back to our black on red style.
1>><<

1>>color=black bgcolor=red<< Some text, black on red. 2>>color=silver bgcolor=blue<< A nested div via >><< style that is silver on blue. 2>><< Back to our black on red style. 1>><<

Implementation:

This is based on the existing >><< WikiStyle Block markup found at roughly line 390 of stdmarkup.php.

 
(:source lang=php:)
 // [Feral:043/07@14:54] Adapted from stdmarkup.php, line 390 or so.
 Markup('^>>>', '<^<<',
   '/^(\\d*?)&gt;&gt;(.+?)&lt;&lt;(.*)$/',
   '(:div$1:)%div $2 apply=div%$3 ');
 Markup('^>>><<<', '<^>>>',
   '/^(\\d*?)&gt;&gt;&lt;&lt;/',
   '(:div$1end:)');
(:sourcend:)

My personal wish is for this (or similar) to be included in the core.

Cute WikiStylesPlus trick:

NOTE: This needs WikiStylesPlus activated to work.
However the idea is that any defined WikiStyle can be used, just as you would expect, is illustrated.

1>>important<<
This is similar to the color proof.
2>>tip<<
Save we are using [[Cookbook/WikiStylesPlus]]' @@>>tip<<@@ nested in a @@>>important<<@@. Neato! ;)
2>><<
Now we are back to our @@>>important<<@@ style, just like we return to the silver on blue style above.
1>><<

1>>important<< This is similar to the color proof. 2>>tip<< Save we are using WikiStylesPlus' >>tip<< nested in a >>important<<. Neato! ;) 2>><< Now we are back to our >>important<< style, just like we return to the silver on blue style above. 1>><<


Proposal #2

Proposed markup:

>>>color=black bgcolor=red<<<
Some text, black on red.
>>>color=silver bgcolor=blue<<<
A nested div via [@>>><<<@] style that is silver on blue.
>>>color=white bgcolor=black<<<
Nested again, 3rd level now; SAME markup([@>>><<<@]);

White on black
>>><<<
Back to second layer, silver on blue
>>><<<
Back to our black on red style.
>>><<<
%div >color=black bgcolor=red apply=div%<

Some text, black on red.

%div >color=silver bgcolor=blue apply=div%<

A nested div via >>><<< style that is silver on blue.

%div >color=white bgcolor=black apply=div%<

Nested again, 3rd level now; SAME markup(>>><<<);

White on black

%div > apply=div%<

Back to second layer, silver on blue

%div > apply=div%<

Back to our black on red style.

%div > apply=div%<

Implementation:

 
(:source lang=php:)
 $DepthCounter = 10;
 function FeralDivCounter($attr, $extra)
 {
     global $DepthCounter;
     $DepthCounter++;
     $out = "(:div{$DepthCounter}:)%div {$attr} apply=div%{$extra} \n";
     return $out;
 }
 function FeralDivCounterEnd()
 {
     global $DepthCounter;
     $out = "(:div{$DepthCounter}end:)";
     $DepthCounter--;
     return $out;
 }
 Markup('^>>>>', '<^<<',
   '/^&gt;&gt;&gt;(.+?)&lt;&lt;&lt;(.*)$/e',
   "FeralDivCounter(PSS('$1'),PSS('$2'))");
 Markup('^>>>><<<<', '<^>>>>',
   '/^&gt;&gt;&gt;&lt;&lt;&lt;$/e',
   "FeralDivCounterEnd()");
(:sourceend:)

Comments

Note Although this works (well it seems), I am not sure if this is the best way to go about this idea.

Regardless, this method uses the three less/greater than signs to denote a smart style block; In essence the wiki will take care of figuring out what number should be assigned to the div. This makes the >>><<< very easy to use as you do not have to worry what number to assign the div, and as an added bonus collisions when including a desperate page should not exist, albeit I have not tried that as of this writing.

It is also nice how >>><<< relates to the existing >><< style block; I presume this will be a easy conceptual leap for users.

However, I am unsure if the initial presented style 1>><< still has value. Do we need specific layer control with the newer automatic numbering scheme?

Also please note that $DepthCounter is initially set to 10; This should allow for space for existing numbered divs, I presume.

The entire premise of this method is to increment a counter each time we are triggered by the >>><<< markup, and decrement same counter when we are triggered by the end style; This counter is used for the div layer number and is passed to the (:div:) directive.

Proposal #2 addendum.

Idea:

Something like our >>>style<<< but that also has a section that is the same level; In essence the normal >>style<< termination method;

For markup perhaps >>>>style<<<< *shrug*;

In essence:

 >>>frame<<<
 In frame
 >>>quote<<<
 In quote
 >>>>quotefrom<<<<
 in quote from;
 >>><<<
 Back to frame.
 >>><<<

Example

This is perfect for and inspired by Cookbook:ToDo-Comments

%define=comment-bubble color=black bgcolor=#eeeeff padding='6px 10px' font-size='11px' line-height='11px'%
%define=comment-author color=black bgcolor=#ffffff padding='2px 8px' font-size='smaller' border='1px solid #eeeeff' float=right%
%define=response-bubble color=black bgcolor=#ffffff padding='6px 10px' border='1px solid #ddddff' font-size='11px' line-height='11px'%
%define=response-author color=black bgcolor=#ddddff padding='2px 8px' font-size='smaller' border='none' float=right%
%define=feature-line-title color=#333 text-decoration=underline%

>>>response-bubble<<<
A user comment
>>>>response-author<<<<
The author's response.
>>><<<
%div >response-bubble apply=div%<

A user comment

%div >>response-author apply=div%<<

The author's response.

%div > apply=div%<

Implementation:

Placed directly under the implementation of proposal #2 in my setup.

 
(:source lang=php:)
 function FeralDiv($attr, $extra)
 {
     global $DepthCounter;
     $out = "(:div{$DepthCounter}:)%div {$attr} apply=div%{$extra} \n";
     return $out;
 }
 Markup('^>>>>', '<^>>>',
   '/^&gt;&gt;&gt;&gt;(.+?)&lt;&lt;&lt;&lt;(.*)$/e',
   "FeralDiv(PSS('$1'),PSS('$2'))");
(:sourceend:)

Comments

This is the same idea as the >>><<< markup style, save do not increment our counter; So we end up terminating the existing block, just as the >>style<< does;

I am not keen on the implemented markup up but *shrug* It works.


00887 Comments...

Very interesting approach. I had been thinking of using multiple '>>>'s to differentiate nested divs, as in

>>color=black bgcolor=red<<
Some text, black on red.
>>>color=silver bgcolor=blue<<<
A nested div that is silver on blue.
>>><<<
Back to our black on red style.
>><<

Perhaps the use of explicit digits is easier to distinguish than trying to count angle brackets. It also resolves the issue of trying to figure out the relationship between the angle brackets and the corresponding (:div:) markers.

I'll definitely think about this one -- I'd really like to hear any other opinions on this one.

Pm

Pm - I prefer your >>1<<, >>2<< suggestion to 1>><<, 2>><<. That said, it does make the connection clearer and it is slightly easier to read, though I don't think >>><<< >>>><<<< is all that hard to read. - JonHaupt