Revision [14463]
This is an old revision of SimpleTables made by TormodHaugen on 2006-06-04 18:14:34.
Simple Table markup for Wikka
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>), and also cells spaning several columns and/or rows.
Usage
Basic delimiter is two pipes (||). This will start a normal datacell.
Enhanced features are enabled by putting modifiers between the pipes:
- A header cell is started with a equals sign (|=|).
- A cell span is started with numbers seperated by a comma. (|2| = colspan="2", |2,2| = col+rowspan ="2" each, |,2| = rowspan="2" only).
Each row must be ended by a basic (or any, actually) delimiter.
A table is ended when no cell is open and there is any data except a delimiter at the start of the line, or at the end of the page's data.
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).
TODO
- better delimiters. please advice.
- caption (currently planned: |c|)
- summary (currently planned: |s|)
- close row at end of line (if people does not want to be able to spread a cell over multiple lines).
- fix known issue (different behavior if previous todo is implemented or not).
Code
Patches is for Wikka Wakka Wiki 1.1.6.1
First comes new and improved patch for wakka.php and wikka.css - then comes old patches for the same. Revert the latter pair, install the former pair. :)
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
Below is the new patch containing headers and col/rowspan. Remember to remove the old patch (it is at the bottom of the page):
--- wakka.php.orig 2006-05-18 12:56:27.000000000 +0200
+++ wakka.php 2006-06-04 23:20:56.000000000 +0200
@@ -28,12 +28,16 @@
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 (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>');
@@ -45,11 +49,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;
}
+ // table. trigger means: 0==no table, 1==in table no cell, 2==in table data cell, 3==in table header cell
+ if ( preg_match("/^\|(=)?(\d*)?(?:,)?(\d*)?\|(\n)?$/", $thing, $matches) ) {
+ //First catch is header, second is colspan, third is rowspan, fourth is linebreak.
+ if ( $trigger_table == 0 ) $rs = "<table class=\"wikka\">\n<tr>";
+ else if ( $trigger_table == 1 ) $rs = "<tr>";
+ else if ( $trigger_table == 2 ) $rs = "</td>";
+ else if ( $trigger_table == 3 ) $rs = "</th>";
+
+ 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 "<";
@@ -371,6 +405,7 @@
"======|=====|====|===|==|". # headings
"\n([\t~]+)(-|&|[0-9a-zA-Z]+\))?|". # indents and lists
"\{\{.*?\}\}|". # action
+ "\|[^\|]*?\|(?:\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 +417,4 @@
echo ($text);
wakka2callback('closetags');
-?>
\ No newline at end of file
+?>
+++ wakka.php 2006-06-04 23:20:56.000000000 +0200
@@ -28,12 +28,16 @@
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 (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>');
@@ -45,11 +49,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;
}
+ // table. trigger means: 0==no table, 1==in table no cell, 2==in table data cell, 3==in table header cell
+ if ( preg_match("/^\|(=)?(\d*)?(?:,)?(\d*)?\|(\n)?$/", $thing, $matches) ) {
+ //First catch is header, second is colspan, third is rowspan, fourth is linebreak.
+ if ( $trigger_table == 0 ) $rs = "<table class=\"wikka\">\n<tr>";
+ else if ( $trigger_table == 1 ) $rs = "<tr>";
+ else if ( $trigger_table == 2 ) $rs = "</td>";
+ else if ( $trigger_table == 3 ) $rs = "</th>";
+
+ 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 "<";
@@ -371,6 +405,7 @@
"======|=====|====|===|==|". # headings
"\n([\t~]+)(-|&|[0-9a-zA-Z]+\))?|". # indents and lists
"\{\{.*?\}\}|". # action
+ "\|[^\|]*?\|(?:\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 +417,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-06-04 23:58:44.000000000 +0200
@@ -412,3 +412,18 @@
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;
+}
+table.wikka th {
+ border: 1px solid #ccc;
+ padding: .1em .25em;
+}
+++ wikka.css 2006-06-04 23:58:44.000000000 +0200
@@ -412,3 +412,18 @@
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;
+}
+table.wikka th {
+ border: 1px solid #ccc;
+ padding: .1em .25em;
+}
OLD patch for ./formatters/wakka.php is here, this is the one to revert:
--- 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 "<";
@@ -70,6 +103,17 @@
{
return ("<div class=\"clear\"> </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
+?>
+++ 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 "<";
@@ -70,6 +103,17 @@
{
return ("<div class=\"clear\"> </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
+?>
Old patch for ./css/wikka.css is here, remove this one if you didn't make the css yourself.
--- 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;
+}
+++ 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 / tell me of any suggestions. --TormodHaugen
CategoryUserContributions