DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:rowspansfix2

Yet another way to make rowspan possible

syntax

colspan:

| 1-1 | 1-2 | 1-3 |
| 2-1 |^ 2-3 |
| 3-1 || 3-3 |

rowspan:

| 1-1 | 1-2 | 1-3 |
| 2-1 ^^ 2-3 |
| 3-1 ^| 3-3 |
  • 2-2 and 3-2 is colspan or rowspan.
  • 2-3 is header cell.
  • 3-3 is normal cell.

changes

xhtml.php:

*   function tableheader_open($colspan = 1, $rowspan = 1, $align = NULL){
        $this->doc .= '<th';
        if ( !is_null($align) ) {
            $this->doc .= ' class="'.$align.'align"';
        }
        if ( $colspan > 1 ) {
            $this->doc .= ' colspan="'.$colspan.'"';
        }
+       if ( $rowspan > 1 ) {
+           $this->doc .= ' rowspan="'.$rowspan.'"';
+       }
        $this->doc .= '>';
    }
 
    function tableheader_close(){
        $this->doc .= '</th>';
    }
 
*   function tablecell_open($colspan = 1, $rowspan = 1, $align = NULL){
        $this->doc .= '<td';
        if ( !is_null($align) ) {
            $this->doc .= ' class="'.$align.'align"';
        }
        if ( $colspan > 1 ) {
            $this->doc .= ' colspan="'.$colspan.'"';
        }
+       if ( $rowspan > 1 ) {
+           $this->doc .= ' rowspan="'.$rowspan.'"';
+       }
        $this->doc .= '>';
    }

metadata.php & renderer.php

* function tableheader_open($colspan = 1, $rowspan = 1, $align = NULL){}
  function tableheader_close(){}
 
* function tablecell_open($colspan = 1, $rowspan = 1, $align = NULL){}

handler.php:

    function tableCell($call) {
        if ( !$this->firstCell ) {
 
            // Increase the span
            $lastCall = end($this->tableCalls);
 
            // A cell call which follows an open cell means an empty cell so span
+           if ( $lastCall[0] == 'tableheader_open' ) {
+                $this->tableCalls[] = array('rowspan',array(),array(),$call[2]);
+           }
*           else if ( $lastCall[0] == 'tablecell_open' ) {
                 $this->tableCalls[] = array('colspan',array(),array(),$call[2]);
            }

and

    function finalizeTable() {
 
        // Add the max cols and rows to the table opening
        if ( $this->tableCalls[0][0] == 'table_open' ) {
            // Adjust to num cols not num col delimeters
            $this->tableCalls[0][1][] = $this->maxCols - 1;
            $this->tableCalls[0][1][] = $this->maxRows;
        } else {
            trigger_error('First element in table call list is not table_open');
        }
*       $preColKey = 0;
*       $curColKey = 0;
*       $preRowKey = array();
*       $curRowKey = array();
*        $row = -1;
*       $col = -1;
        $toDelete = array();
 
        // Look for the colspan elements and increment the colspan on the
        // previous non-empty opening cell. Once done, delete all the cells
        // that contain colspans
        foreach ( $this->tableCalls as $key => $call ) {
 
            if ( $call[0] == 'tablerow_open' ) {
 
*               $row++;
*               $col = -1;
 
            } else if ( $call[0] == 'tablecell_open' || $call[0] == 'tableheader_open' ) {
 
*               $col++;
*               $preColKey = $curColKey;
*               $preRowKey[$col] = $curRowKey[$col];
*               $curColKey = $curRowKey[$col] = $key;
*               $this->tableCalls[$key][1][1] = 1;  //fix me!
 
            } else if ( $call[0] == 'table_align' ) {
 
                // If the previous element was a cell open, align right
                if ( $this->tableCalls[$key-1][0] == 'tablecell_open' || $this->tableCalls[$key-1][0] == 'tableheader_open' ) {
*                   $this->tableCalls[$key-1][1][2] = 'right';
 
                // If the next element if the close of an element, align either center or left
                } else if ( $this->tableCalls[$key+1][0] == 'tablecell_close' || $this->tableCalls[$key+1][0] == 'tableheader_close' ) {
*                   if ( $this->tableCalls[$curColKey][1][2] == 'right' ) {
*                       $this->tableCalls[$curColKey][1][2] = 'center';
                    } else {
*                       $this->tableCalls[$curColKey][1][2] = 'left';
                    }
 
                }
 
                // Now convert the whitespace back to cdata
                $this->tableCalls[$key][0] = 'cdata';
 
            } else if ( $call[0] == 'colspan' ) {
*               if( $col > 0 ) {
*                   $i = $preColKey;
*                   if( $this->tableCalls[$i][1][1] == 1 ) {
*                       $curColKey = $i;
*                       $this->tableCalls[$i][1][0]++;
*                       $toDelete[] = $key-1;
*                       $toDelete[] = $key+1;
*                   }
*               }
*               $toDelete[] = $key;
*           } else if ( $call[0] == 'rowspan' ) {
*               if( $row > 0 ) {
*                   $i = $preRowKey[$col];
*                   if( $this->tableCalls[$i][1][0] == 1 ) {
*                       $curRowKey[$col] = $i;
*                       $this->tableCalls[$i][1][1]++;
*                       $toDelete[] = $key-1;
*                       $toDelete[] = $key+1;
*                   }
*               }
*               $toDelete[] = $key;
            }
        }
tips/rowspansfix2.txt · Last modified: 2021-12-30 19:04 by patric

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