Revision [14265]

This is an old revision of SimpleTables made by TormodHaugen on 2006-05-18 07:27:56.

 

Simple Table markup for Wikka



I've modified ./formatters/wakka.php to interpret || as a table/cell delimiter.

You can use other WikkaMarkup inside the table, and if you forget to close the table, it will close by itself before the footer.

See it in use here: http://wiki.tormodh.net/SimpleTable

Usage


A new row is created by starting a line with ||. Each new cell is started by another ||. A row is ended by 1) Either ending a line with || and a newline. 2) Starting a new line with ||. The table is ended by having || on the end of one line, and not opening another row at the next (active) line. One empty line does not end the table.

Code


Patches is for Wikka Wakka Wiki 1.1.6.1

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


Patch for ./formatters/wakka.php is here, work it by putting it in the formatters directory:

--- wakka.php.orig  2006-05-18 12:56:27.000000000 +0200
+++ wakka.php   2006-05-15 21:29:54.000000000 +0200
@@ -28,12 +28,15 @@
        static $trigger_strike = 0;
        static $trigger_inserted = 0;
        static $trigger_center = 0;
+       static $trigger_table = 0;
        static $trigger_l = array(-1, 0, 0, 0, 0, 0);
 
        global $wakka;
 
        if ((!is_array($things)) && ($things == 'closetags'))
        {
+           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>');
@@ -45,11 +48,41 @@
            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_table = $trigger_floatl = $trigger_inserted = $trigger_deleted = $trigger_italic = $trigger_keys = 0;
            $trigger_l = array(-1, 0, 0, 0, 0, 0);
            $trigger_monospace = $trigger_notes = $trigger_strike = $trigger_underline = 0;
            return;
        }
+       if ($trigger_table == 0)
+       {
+           //We're not in a table, check to see if we want to create one
+           if (preg_match("/\n\|\|/s", $thing, $matches)) {
+               $trigger_table = 2;
+               return "<br />\n<table class=\"wikka\">\n<tr><td>";
+           }
+       }
+       else if ($trigger_table == 1)
+       {
+           //We're in a table, but not in a cell. Create new row+cell? or end table?
+           if (preg_match("/\|\|/s", $thing, $matches))
+           {
+               $trigger_table = 2;
+               return "<tr><td>";
+           }
+           else if ($thing != "")
+           {
+               $trigger_table = 0;
+               return "</table>\n".wakka2callback($things);
+           }
+       }
+       else if ($trigger_table == 2)
+       {
+           //We're in a cell, check for newline if we need a new row + last ended.
+           if (preg_match("/\n\|\|/s", $thing, $matches))
+           {
+               return "</td></tr>\n<tr><td>";
+           }
+       }
        // convert HTML thingies
        if ($thing == "<")
            return "&lt;";
@@ -70,6 +103,17 @@
        {
            return ("<div class=\"clear\">&nbsp;</div>\n");
        }
+       // end cell + row.
+       else if (preg_match("/\|\|\n/s", $thing, $matches))
+       {
+           $trigger_table = 1;
+           return "</td></tr>\n";
+       }
+       // end cell + start cell. all other stuff handeled before.
+       else if ($thing == "||")
+       {
+           return "</td><td>";
+       }
        // keyboard
        else if ($thing == "#%")
        {
@@ -371,6 +415,7 @@
    "======|=====|====|===|==|".                                                            # headings
    "\n([\t~]+)(-|&|[0-9a-zA-Z]+\))?|".                                                     # indents and lists
    "\{\{.*?\}\}|".                                                                         # action
+   "\n\|\||\|\|\n|\|\||".                                                                  # Simple Tables
    "\b[A-ZÄÖÜ][A-Za-zÄÖÜßäöü]+[:](?![=_])\S*\b|".                                            # InterWiki link
    "\b([A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*)\b|".                                # CamelWords
    "\n".                                                                                   # new line
@@ -382,4 +427,4 @@
 echo ($text);
 wakka2callback('closetags');
 
-?>
\ No newline at end of file
+?>


Patch for ./css/wikka.css is here, work it as above (put the file in the css directory).

--- wikka.css.orig  2006-05-18 13:05:30.000000000 +0200
+++ wikka.css   2006-05-05 00:18:36.000000000 +0200
@@ -412,3 +412,14 @@
    color: #993333;
    text-decoration: none;
 }
+
+/* SimpleTable style */
+table.wikka {
+   border: 2px solid #ccc;
+   border-collapse: collapse;
+   border-spacing: 0;
+}
+table.wikka td {
+   border: 1px solid #ccc;
+   padding: .1em .25em;
+}


Please comment / edit this code / tell me if it isn't good enough. --TormodHaugen

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