Revision [14659]
This is an old revision of SimpleTables made by DarTar on 2006-06-21 07:42:48.
Simple Table markup for Wikka
See also
Test at
- my testwiki running trunk install with all SimpleTables features.
SVN
2006-06-21Patch committed to the SVN repository - to be included in 1.1.6.3:
- Ticket:230
I've hacked together a simple table markup for WikkaWiki; it is working it's way from a "layout" table markup to an accessible 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, scope attributes for headers, table sections (<thead>, <tbody>, <tfoot>).
Basic Usage
Example:
||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 (||).
- Use the delimiter to start a new table, row and/or cell.
- The current row is ended with a delimiter at the end of a line.
- The table is ended by starting the next line with anything else than a new delimiter after ending a row.
"Advanced" Usage
Example:
|?This is a token summary, must be first line in table markup. PS is between single pipes!|
|!|The Caption||
|#h|
|=|First Column|=|Second Column||
|#b|
||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)||
|#f|
|=|First Column|=|Second Column||
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).
- An optional caption for the table can be put behind a exclamation mark'ed delimiter (|!|) and a normal delimiter. Needs to be alone on the line!
- A summary (for accessability) can be given in a delimiter started by a question mark (|?Summary|). Needs to be alone on the line, and first in the markup!
- Optional row and col scope attributes for headers can be added as |=r| and |=c|.
- Optional thead, tbody and tfoot sections are generated by adding on a separate line |#h|, |#b|, |#f|
- Each row must (still) be ended by a basic (or any, actually) delimiter.
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
- better delimiters? Please advice.
- header cells Done.
- col/rowspan Done.
- caption Done.
- summary Done.
- th scope attribute Done.
- thead/tbody/tfoot Done.
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 "<";
@@ -414,6 +475,7 @@
"\*\*|\'\'|\#\#|\#\%|@@|::c::|\>\>|\<\<|££|¥¥|\+\+|__|<|>|\/\/|". # 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
+++ 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 "<";
@@ -414,6 +475,7 @@
"\*\*|\'\'|\#\#|\#\%|@@|::c::|\>\>|\<\<|££|¥¥|\+\+|__|<|>|\/\/|". # 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; }
+++ 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