DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:tableswithrowspans

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
tips:tableswithrowspans [2009-09-22 21:25] – fixed links achtips:tableswithrowspans [2009-11-08 21:16] (current) – removed non working tip for rowspan HåkanS
Line 1: Line 1:
-====== Tables with Rowspan Support ====== 
-I could not use Dokuwiki without tables with rowspans. I use tables to draw server cabinets and since we don't have entirely 1u servers I needed to have the ability to span rows. 
  
-This code changes the formating rules for tables. It also makes Dokuwiki compatible with TWiki table formating, which is also a plus. I changed the function of the "hat" symbol so headings now are done using "stars" on each side of the word. 
- 
-John Van Boxtel 
- 
- 
-> Hi John. I realy REALY tried to port your mod to a plugin or just to redo it in the new dokuwiki lexer .. But it was absoluttly not possible for me to find all the code pieces hat do the new reorganisizion. For this reason i request to finaly insert rowspan into the default code. >:|   
- 
->Tharo <tharo (a)(t) snowdesign (d)(o)(t) de 
- 
-This page seems to be out of date. The code does not integrate into the current version of dokuwiki. james.johnson at publitek dotcom FIXME 
- 
-===== Code Changes ===== 
-In //inc/parser.php// replace the __tableformat()__ function with this one: 
-<code php> 
-function tableformat($block) { 
-  $block = trim($block); 
-  $lines = split("\n",$block); 
-  $ret = ""; 
-  //build a row array 
-  for($r=0; $r < count($lines); $r++){ 
-    echo $r; 
-    $line = $lines[$r]; 
-    $c = -1; //prepare colcounter) 
-    //remove last seperator and trailing whitespace 
-    $line = preg_replace('/[\|\~]\s*$/', '', $line); 
-    for($chr=0; $chr < strlen($line); $chr++){ 
-      if($line[$chr] == '|'){ 
-        $c++; 
-        $rows[$r][$c]['data'] = ''; 
-        $rows[$r][$c]['rowspan']= FALSE; 
-      }else{ 
-        //if(!isset($rows[$r][$c]['data'])) { $rows[$r][$c]['data'] = ''; } 
-        $rows[$r][$c]['data'].= $line[$chr]; 
-        $rows[$r][$c]['rowspan']= FALSE; 
-      } 
-    } 
-  } 
- 
-  //build table 
-  $ret .= "</p>\n<table border=\"1\">\n"; 
-  for($r=0; $r < count($rows); $r++){ 
-    for ($c=0; $c < count($rows[$r]); $c++){ 
-      //$data = trim($rows[$r][$c]['data']); 
-      $data = $rows[$r][$c]['data']; 
-      if(preg_match('/\^/', $data)) { 
-         $rows[$r][$c]['rowspan'] = TRUE; 
-      } 
-    } 
-  } 
- 
-  for($r=0; $r < count($rows); $r++){ 
- 
-    $ret .= "  <tr>\n"; 
- 
-    for ($c=0; $c < count($rows[$r]); $c++){ 
-      $cspan = 1; 
-      $rspan = 1; 
-      $data = trim($rows[$r][$c]['data']); 
-      $totalrows = count($rows[$r]); 
-      $r++; // not sure why you have to do this... 
-      if($rows[$r][$c]['rowspan']){ 
-        for($x = $r; $x < count($rows); $x++) { 
-          if($rows[$x][$c]['rowspan']){ 
-             $rspan++; 
-          } 
-          // check to see if next row continues to span, or break 
-          $r++; //to check array $r+1 
-          if($rows[$x][$c]['rowspan'] != TRUE) { $x = count($rows);  } 
-          $r--; //to check array $r+1 
-        } 
-      } 
-      $r--; // not sure why you have to do this... 
- 
-      //join cells if next is empty 
-      while($c < count($rows[$r])-1 && $rows[$r][$c+1]['data'] == ''){ 
-        $c++; 
-        $cspan++; 
-      } 
-      if($cspan > 1){ 
-        $cspan = ' colspan="'.$cspan.'"'; 
-      }else{ 
-        $cspan = ''; 
-      } 
- 
-      if($rspan > 1){ 
-        $rspan = ' rowspan="'.$rspan.'"'; 
-      }else{ 
-        $rspan = ''; 
-      } 
- 
-      //var_dump($rspan); 
-      if (preg_match('/\*(.*)\*/', $data, $match)) { 
-        $data = $match[1]; 
-        $ret .= "    <th class=\"inline\"$cspan$rspan>$data</th>\n"; 
-      } elseif (!preg_match('/\^/', $data)) { 
-     //   var_dump($rspan); 
-        $ret .= "    <td class=\"inline\"$cspan$rspan>$data</td>\n"; 
-      } 
-    } 
-    $ret .= "  </tr>\n"; 
-  } 
-  $ret .= "</table>\n<p>"; 
- 
-  return $ret; 
-} 
-</code> 
- 
- 
-===== Examples ===== 
-**NOTICE: These will only work properly if splitbrain.org implements the changes** 
- 
-Here is an example of blank box without vertical span.  Notice the new heading format: 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | No Rowspan This Line | Row 2 Col 3        | 
-| *Heading 5*  |                      | Row 3 Col 3        | 
- 
-As you can see, the "stars" make the headings now: 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | No Rowspan This Line | Row 2 Col 3        | 
-  | *Heading 5*  |                      | Row 3 Col 3        | 
- 
-Here is an example of a vertical span.  Notice the new use of the "hat": 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | No Rowspan This Line | Row 2 Col 3        | 
-| *Heading 5*  | ^                    | Row 3 Col 3        | 
- 
-As you can see, the "stars" make the headings now: 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | No Rowspan This Line | Row 2 Col 3        | 
-  | *Heading 5*  | ^                    | Row 3 Col 3        | 
- 
- 
-===== Wiki:Syntax Page ===== 
- 
-Next you probable want to update the wiki:syntax page to show the new formating.  Below is an updated raw wiki formated  
-table section. 
- 
-<code> 
-===== Tables ===== 
- 
-DokuWiki supports a simple syntax to create tables. 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | Colspan This Line (note double pipe      || 
-| *Heading 5*  | Row 3 Col 2          | Row 3 Col 3        | 
- 
-Table rows have to start and end with a ''|'' for rows. Headers are made by putting ''*'' around the text. 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | Colspan This Line (note double pipe      || 
-  | *Heading 5*  | Row 3 Col 2          | Row 3 Col 3        | 
- 
-To connect cells horizontally just make the next cell completely empty as shown above. Be sure to have always the same amount of cell separators!  Vertical Tableheaders are possible, too. 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | No Colspan This Line |                    | 
-| *Heading 5*  | Row 3 Col 2          | Row 3 Col 3        | 
- 
-As you can see it's the cell separator before a cell which decides about the formating: 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | Colspan This Line                        || 
-  | *Heading 5*  | Row 3 Col 2          | Row 3 Col 3        | 
- 
-Vertical spans (rowspan) are now possible using a "hat": 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | Rowspan This Line    | Row 2 Col 3        | 
-| *Heading 5*  | ^                    | Row 3 Col 3        | 
- 
-This is done like this: 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | Rowspan This Line    | Row 2 Col 3        | 
-  | *Heading 5*  | ^                    | Row 3 Col 3        | 
- 
-Here is an example of blank box without vertical span: 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | No Rowspan This Line | Row 2 Col 3        | 
-| *Heading 5*  |                      | Row 3 Col 3        | 
- 
-As you can see, the "hat" makes all the difference: 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | No Rowspan This Line | Row 2 Col 3        | 
-  | *Heading 5*  |                      | Row 3 Col 3        | 
-</code> 
- 
->The new way to make rowspan possible [[rowspansfix]] or [[rowspansfix2]] 
->>Can't find those? 
- 
- 
- 
- 
-===== Tables ===== 
- 
-DokuWiki supports a simple syntax to create tables. 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | Colspan This Line (note double pipe      || 
-| *Heading 5*  | Row 3 Col 2          | Row 3 Col 3        | 
- 
-Table rows have to start and end with a ''|'' for rows. Headers are made by putting ''*'' around the text. 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | Colspan This Line (note double pipe      || 
-  | *Heading 5*  | Row 3 Col 2          | Row 3 Col 3        | 
- 
-To connect cells horizontally just make the next cell completely empty as shown above. Be sure to have always the same amount of cell separators!  Vertical Tableheaders are possible, too. 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | No Colspan This Line |                    | 
-| *Heading 5*  | Row 3 Col 2          | Row 3 Col 3        | 
- 
-As you can see it's the cell separator before a cell which decides about the formating: 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | Colspan This Line                        || 
-  | *Heading 5*  | Row 3 Col 2          | Row 3 Col 3        | 
- 
-Vertical spans (rowspan) are now possible using a "hat": 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | Rowspan This Line    | Row 2 Col 3        | 
-| *Heading 5*  | ^                    | Row 3 Col 3        | 
- 
-This is done like this: 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | Rowspan This Line    | Row 2 Col 3        | 
-  | *Heading 5*  | ^                    | Row 3 Col 3        | 
- 
-Here is an example of blank box without vertical span: 
- 
-|              | *Heading 1*          | *Heading 2*        | 
-| *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-| *Heading 4*  | No Rowspan This Line | Row 2 Col 3        | 
-| *Heading 5*  |                      | Row 3 Col 3        | 
- 
-As you can see, the "hat" makes all the difference: 
- 
-  |              | *Heading 1*          | *Heading 2*        | 
-  | *Heading 3*  | Row 1 Col 2          | Row 1 Col 3        | 
-  | *Heading 4*  | No Rowspan This Line | Row 2 Col 3        | 
-  | *Heading 5*  |                      | Row 3 Col 3        | 
tips/tableswithrowspans.1253647523.txt.gz · Last modified: 2009-09-22 21:25 by ach

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki