Revision [14607]

This is an old revision of SimpleTables made by TormodHaugen on 2006-06-15 09:33:19.

 

Simple Table markup for Wikka


See also
Test at


I've hacked together a simple table markup for WikkaWiki; it is working it's way from a "layout" table markup to a data table markup.

Currently it supports table header elements (<th>) and table data elements (<td>), cells spanning several columns and/or rows, table summary and caption.
 

Basic Usage



Example (is not in use, cannot be demonstrated here):

||Row 1 Column 1||Row 1 Column 2||Row 1 Column 3||
||Row 2 Column 1||Row 2 Column 2||Row 2 Column 3||

The delimiter is two pipes (||).

 

"Advanced" Usage



Example (is not in use, cannot be demonstrated here):

|?This is a token summary, must be first line in table markup. PS is between single pipes!|
|!|The Caption||
|=|First Column|=|Second Column||
||First datacell||Second Datacell||
|2|A datacell spanning two columns||
|,2|A datacell spanning two rows||A cell on the right||
||Another cell on the right (due to previous rowspan'd cell)||

Enhanced features are enabled by putting modifiers between the pipes.

 

Known Issues


Ending the table with a || delimiter without a newline adds another cell/column. (ie: if there is no more content after the table, or if there is a space after the delimiter).

Wanted


I want input on bugs/issues - and on wanted functionality / suggestion on the markup.

TODO



Code


Patches for download

It seems as if there might be some trouble with grabbing and patching the code; these files are tested against the 1.1.6.2 download and should work:


Patches are for Wikka Wakka Wiki 1.1.6.2. Should be easy to implement manually (or fuzzy) for other versions.

To pach a file under Linux; put the patch file in the same directory as the file itself and run with the command:
patch -p0 -l < patch_name.patch


Revert (uninstall ;)) with the command:
patch -p0 -l -R < patch_name.patch

 

Save as simpletables.patch in ./formatters/ and apply from there (or do it manually).

--- wakka.php.orig  2006-06-14 18:42:49.000000000 +0200
+++ wakka.php   2006-06-14 18:42:55.000000000 +0200
@@ -26,6 +26,7 @@
        static $indentClosers = array();
        static $newIndentSpace= array();
        static $br = 1;
+       static $trigger_table = 0;
        static $trigger_bold = 0;
        static $trigger_italic = 0;
        static $trigger_underline = 0;
@@ -48,6 +49,9 @@
 
        if ((!is_array($things)) && ($things == 'closetags'))
        {
+           if (2 < $trigger_table) echo ('</th></tr>');
+           else if (1 < $trigger_table) echo ('</td></tr>');
+           if (0 < $trigger_table) echo ('</table>');
            if ($trigger_strike % 2) echo ('</span>');
            if ($trigger_notes % 2) echo ('</span>');
            if ($trigger_inserted % 2) echo ('</span>');
@@ -59,11 +63,68 @@
            if ($trigger_bold % 2) echo('</strong>');
            for ($i = 1; $i<=5; $i ++)
                if ($trigger_l[$i] % 2) echo ("</h$i>");
-           $trigger_bold = $trigger_center = $trigger_floatl = $trigger_inserted = $trigger_deleted = $trigger_italic = $trigger_keys = 0;
+           $trigger_bold = $trigger_center = $trigger_floatl = $trigger_inserted = $trigger_deleted = $trigger_italic = $trigger_keys = $trigger_table = 0;
            $trigger_l = array(-1, 0, 0, 0, 0, 0);
            $trigger_monospace = $trigger_notes = $trigger_strike = $trigger_underline = 0;
            return;
        }
+       if ( preg_match("/^\|(\?)(.*?)?\|(\n)?$/", $thing, $matches) ) {
+           if ( $trigger_table == 0 ) {
+               $trigger_table = 1;
+               //TODO escape text for safety
+               return '<table class="wikka" summary="'.$matches[2].'">'."\n";
+           }
+       }
+       // table. trigger means: 0==no table, 1==in table no cell, 2==in table data cell, 3==in table header cell
+       else if ( preg_match("/^\|(=|!)?(\d*)?(?:,)?(\d*)?\|(\n)?$/", $thing, $matches) ) {
+           //First catch is header|caption|summary, second is colspan, third is rowspan, fourth is linebreak.
+           if ( $trigger_table == 0 )
+           {
+               $rs = "<table class=\"wikka\">\n";
+               if ($matches[1] == "!") {
+                   $trigger_table = 4;
+                   return $rs."<caption>";
+               } else {
+                   $rs .= "<tr>";
+               }
+           }
+           else if ( $trigger_table == 1 ) {
+               if ($matches[1] == "!") {
+                   $trigger_table = 4;
+                   return "<caption>";
+               } else {
+                   $rs = "<tr>";
+               }
+           }
+           else if ( $trigger_table == 2 ) $rs = "</td>";
+           else if ( $trigger_table == 3 ) $rs = "</th>";
+           else if ( $trigger_table == 4 ) {
+               $trigger_table = 1;
+               return "</caption>\n";
+           }
+          
+           if ( $trigger_table > 1 && $matches[4] == "\n") {
+               $trigger_table = 1;
+               return $rs."</tr>\n";
+           }
+          
+           if ( $matches[1] == "=" ) {
+               $trigger_table = 3;
+               $rs .= "<th";
+           } else if ( $matches[1] == "" ) {
+               $trigger_table = 2;
+               $rs .= "<td";
+           }
+           if ( $matches[2] && $matches[2] > 1 ) $rs .= " colspan=\"$matches[2]\"";
+           if ( $matches[3] && $matches[3] > 1 ) $rs .= " rowspan=\"$matches[3]\"";
+          
+           return $rs.">";
+
+       } else if ( $trigger_table == 1 ) {
+           //Are in table, no cell - but not asked to open new: please close and parse again. ;)
+           $trigger_table = 0;
+           return "</table>\n".wakka2callback($things);
+       }
        // convert HTML thingies
        if ($thing == "<")
            return "&lt;";
@@ -414,6 +475,7 @@
    "\*\*|\'\'|\#\#|\#\%|@@|::c::|\>\>|\<\<|&pound;&pound;|&yen;&yen;|\+\+|__|<|>|\/\/|".   # Wiki markup
    "======|=====|====|===|==|".                                                            # headings
    "\n([\t~]+)(-|&|[0-9a-zA-Z]+\))?|".                                                     # indents and lists
+   "\|[^\|]*?\|(?:\n)?|".                                                                  # Simple Tables
    "\{\{.*?\}\}|".                                                                         # action
    "\b[A-ZÄÖÜ][A-Za-zÄÖÜßäöü]+[:](?![=_])\S*\b|".                                            # InterWiki link
    "\b([A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*)\b|".                                # CamelWords


Save as simpletables_css.patch in ./css/ and apply from there (or do it manually).

--- wikka.css.orig  2006-06-14 18:48:36.000000000 +0200
+++ wikka.css   2006-06-14 18:54:27.000000000 +0200
@@ -446,6 +446,11 @@
    border-spacing: 0;
 }
 
+table.wikka th {
+   border: 1px solid #CCC;
+   padding: .1em .25em;
+}
+
 table.wikka td {
    border: 1px solid #CCC;
    padding: .1em .25em;
@@ -600,4 +605,4 @@
 .toolbar .btn-active,
 .toolbar .btn-pressed { border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow; }
 .toolbar .btn-pressed { background: ButtonHighlight; }
-.editornamecss { background-color:#CCCCFF; font-size: 18px; padding: 0 10px; }
\ No newline at end of file
+.editornamecss { background-color:#CCCCFF; font-size: 18px; padding: 0 10px; }



Please comment / tell me of any suggestions. --TormodHaugen

CategoryUserContributions
There are 34 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki