tips:tableswithrowspans
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
wiki:tips:tableswithrowspans [2007-10-20 17:28] – 149.156.124.14 | tips: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 " | ||
- | |||
- | 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 // | ||
- | <code php> | ||
- | function tableformat($block) { | ||
- | $block = trim($block); | ||
- | $lines = split(" | ||
- | $ret = ""; | ||
- | //build a row array | ||
- | for($r=0; $r < count($lines); | ||
- | echo $r; | ||
- | $line = $lines[$r]; | ||
- | $c = -1; //prepare colcounter) | ||
- | //remove last seperator and trailing whitespace | ||
- | $line = preg_replace('/ | ||
- | for($chr=0; $chr < strlen($line); | ||
- | if($line[$chr] == ' | ||
- | $c++; | ||
- | $rows[$r][$c][' | ||
- | $rows[$r][$c][' | ||
- | }else{ | ||
- | // | ||
- | $rows[$r][$c][' | ||
- | $rows[$r][$c][' | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | //build table | ||
- | $ret .= "</ | ||
- | for($r=0; $r < count($rows); | ||
- | for ($c=0; $c < count($rows[$r]); | ||
- | //$data = trim($rows[$r][$c][' | ||
- | $data = $rows[$r][$c][' | ||
- | if(preg_match('/ | ||
- | | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | for($r=0; $r < count($rows); | ||
- | |||
- | $ret .= " | ||
- | |||
- | for ($c=0; $c < count($rows[$r]); | ||
- | $cspan = 1; | ||
- | $rspan = 1; | ||
- | $data = trim($rows[$r][$c][' | ||
- | $totalrows = count($rows[$r]); | ||
- | $r++; // not sure why you have to do this... | ||
- | if($rows[$r][$c][' | ||
- | for($x = $r; $x < count($rows); | ||
- | if($rows[$x][$c][' | ||
- | | ||
- | } | ||
- | // check to see if next row continues to span, or break | ||
- | $r++; //to check array $r+1 | ||
- | if($rows[$x][$c][' | ||
- | $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][' | ||
- | $c++; | ||
- | $cspan++; | ||
- | } | ||
- | if($cspan > 1){ | ||
- | $cspan = ' colspan="' | ||
- | }else{ | ||
- | $cspan = ''; | ||
- | } | ||
- | |||
- | if($rspan > 1){ | ||
- | $rspan = ' rowspan="' | ||
- | }else{ | ||
- | $rspan = ''; | ||
- | } | ||
- | |||
- | // | ||
- | if (preg_match('/ | ||
- | $data = $match[1]; | ||
- | $ret .= " | ||
- | } elseif (!preg_match('/ | ||
- | // | ||
- | $ret .= " | ||
- | } | ||
- | } | ||
- | $ret .= " | ||
- | } | ||
- | $ret .= "</ | ||
- | |||
- | return $ret; | ||
- | } | ||
- | </ | ||
- | |||
- | |||
- | ===== 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 " | ||
- | |||
- | | | *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 " | ||
- | |||
- | | | *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 " | ||
- | |||
- | | | *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. | ||
- | table section. | ||
- | |||
- | < | ||
- | ===== 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 '' | ||
- | |||
- | | | *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! | ||
- | |||
- | | | *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 " | ||
- | |||
- | | | *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 " | ||
- | |||
- | | | *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 | | ||
- | </ | ||
- | |||
- | >The new way to make rowspan possible [[: | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ===== 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 '' | ||
- | |||
- | | | *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! | ||
- | |||
- | | | *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 " | ||
- | |||
- | | | *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 " | ||
- | |||
- | | | *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 | |