Changeset 132

Show
Ignore:
Timestamp:
06/21/2006 06:24:34 AM (3 years ago)
Author:
DarTar
Message:

formatters/wakka.php - Adding thead/tbody/tfoot support to table formatter and relative stylesheet selectors. Credits: Tormod Haugen - #230

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/css/wikka.css

    r129 r132  
    447447} 
    448448 
    449 table.wikka caption{ 
    450         border: 1px dotted #BBB; 
    451         font-size: 90%; 
     449table.wikka caption { 
     450        border: 1px solid #CCC; 
     451        font-size: 95%; 
    452452        color: #666; 
    453453        margin:5px 0; 
     
    455455} 
    456456 
     457table.wikka thead { 
     458        background-color: #DDD; 
     459} 
     460 
     461table.wikka tfoot { 
     462        background-color: #DDD; 
     463} 
     464 
    457465table.wikka th { 
    458466        border: 1px solid #CCC; 
    459467        padding: .1em .25em; 
     468} 
     469 
     470table.wikka thead th { 
     471        background-color: #DDD; 
     472} 
     473 
     474table.wikka tfoot th { 
     475        background-color: #DDD; 
     476} 
     477 
     478table.wikka tbody th { 
     479        background-color: #EEE; 
     480} 
     481 
     482table.wikka tbody tr:hover { 
    460483        background-color: #EEE; 
    461484} 
  • trunk/formatters/wakka.php

    r131 r132  
    4646                static $br = 1; 
    4747                static $trigger_table = 0; 
     48                static $trigger_rowgroup = 0; 
    4849                static $trigger_bold = 0; 
    4950                static $trigger_italic = 0; 
     
    7071                        if (2 < $trigger_table) echo ('</th></tr>'); 
    7172                        else if (1 < $trigger_table) echo ('</td></tr>'); 
     73                        if (2 < $trigger_rowgroup) echo ('</tbody>'); 
     74                        else if (1 < $trigger_rowgroup) echo ('</tfoot>'); 
     75                        else if (0 < $trigger_rowgroup) echo ('</thead>'); 
    7276                        if (0 < $trigger_table) echo ('</table>'); 
    7377                        if ($trigger_strike % 2) echo ('</span>'); 
     
    8791                        return; 
    8892                } 
    89                 if ( preg_match("/^\|(\?)(.*?)?\|(\n)?$/", $thing, $matches) ) { 
    90                         if ( $trigger_table == 0 ) { 
     93 
     94                if ( preg_match("/^\|(\?)(.*?)\|\n$/", $thing, $matches) ) 
     95                { 
     96                        if ( $trigger_table == 0 ) 
     97                        { 
    9198                                $trigger_table = 1; 
    92                                 //TODO escape text for safety 
    9399                                return '<table class="wikka" summary="'.$matches[2].'">'."\n"; 
    94100                        } 
    95101                } 
    96102                // table. trigger means: 0==no table, 1==in table no cell, 2==in table data cell, 3==in table header cell 
    97                 else if ( preg_match("/^\|(=|!)?(c|r)?(\d*)?(?:,)?(\d*)?\|(\n)?$/", $thing, $matches) ) { 
    98                         //First catch is header|caption|summary, second is colspan, third is rowspan, fourth is linebreak. 
    99                         if ( $trigger_table == 4 ) { 
     103                else if ( preg_match("/^\|(=|!|#)?(c|r|h|f|b)?(\d*)?(?:,)?(\d*)?\|(\n)?$/", $thing, $matches) ) 
     104                { 
     105                        //Set up the two variables that will aggregate the html markup 
     106                        $close_part = ''; 
     107                        $open_part  = ''; 
     108                        //First catch is header|caption|rowgroup, second is attribute, third is colspan, fourth is rowspan, fifth is linebreak. 
     109                        if ( $trigger_table == 4 ) 
     110                        { 
    100111                                $trigger_table = 1; 
    101112                                return '</caption>'."\n"; //Can return here, it is closed. 
    102113                        } 
    103                         else if ( $trigger_table == 3 ) $close_part = '</th>'; 
    104                         else if ( $trigger_table == 2 ) $close_part = '</td>'; 
    105                         else if ( $trigger_table == 1 ) $close_part = ''; 
    106                         else $close_part = '<table class="wikka">'."\n"; 
     114                        else if ( $trigger_table == 3 ) 
     115                        { 
     116                                $close_part = '</th>'; 
     117                        } 
     118                        else if ( $trigger_table == 2 ) 
     119                        { 
     120                                $close_part = '</td>'; 
     121                        } 
     122                        else if ( $trigger_table == 1 ) 
     123                        { 
     124                                $close_part = ''; 
     125                        } 
     126                        else 
     127                        { 
     128                                //This is actually opening the table (i.e. nothing at all to close). 
     129                                $close_part = '<table class="wikka">'."\n"; 
     130                        } 
    107131                         
    108                         if ( $trigger_table > 1 && $matches[5] == "\n" ) { 
     132                        if ( $trigger_table > 1 && $matches[5] == "\n" ) 
     133                        { 
    109134                                $trigger_table = 1; 
    110135                                return $close_part .= '</tr>'."\n"; //Can return here, it is closed- 
    111136                        } 
    112137 
    113                         if ( $matches[1] == '!' ) { 
     138                        if ( $matches[1] == '!' ) 
     139                        { 
    114140                                $trigger_table = 4; 
    115141                                $open_part = '<caption>'; 
    116                         } else { 
    117                                 if ( $trigger_table == 1 ) $open_part = '<tr>'; 
    118                                 else $open_part = ''; 
    119  
    120                                 if ( $matches[1] == '=' ) { 
     142                        } 
     143                        else if ( $matches[1] == '#' ) 
     144                        { 
     145                                //If we're here, we want to close any open rowgroup. 
     146                                if (2 < $trigger_rowgroup) 
     147                                { 
     148                                        $close_part .= '</tbody>'."\n"; 
     149                                } 
     150                                else if (1 < $trigger_rowgroup) 
     151                                { 
     152                                        $close_part .= '</tfoot>'."\n"; 
     153                                } 
     154                                else if (0 < $trigger_rowgroup) 
     155                                { 
     156                                        $close_part .= '</thead>'."\n"; 
     157                                } 
     158 
     159                                if ($matches[2] && ($matches[2] == 'h' || $matches[2] == 'f') ) 
     160                                { 
     161                                        //thead or tfoot 
     162                                        if ($matches[2] == 'h') 
     163                                        { 
     164                                                $open_part .= '<thead>'."\n"; 
     165                                                $trigger_rowgroup = 1; 
     166                                        } 
     167                                        else if ($matches[2] == 'f') 
     168                                        { 
     169                                                $open_part .= '<tfoot>'."\n"; 
     170                                                $trigger_rowgroup = 2; 
     171                                        } 
     172                                } 
     173                                else 
     174                                { 
     175                                        //tbody 
     176                                        $open_part .= '<tbody>'."\n"; 
     177                                        $trigger_rowgroup = 3; 
     178                                } 
     179                        } 
     180                        else 
     181                        { 
     182                                $open_part = ''; 
     183                                if ($trigger_rowgroup == 0) 
     184                                { 
     185                                        $open_part .= '<tbody>'."\n"; 
     186                                        $trigger_rowgroup = 3; 
     187                                } 
     188 
     189                                if ( $trigger_table == 1 ) 
     190                                { 
     191                                        $open_part .= '<tr>'; 
     192                                } 
     193 
     194                                if ( $matches[1] == '=' ) 
     195                                { 
    121196                                        $trigger_table = 3; 
    122197                                        $open_part .= '<th'; 
    123                                         if ( $matches[2] ) { 
    124                                                 if ( $matches[2] == 'c' ) $open_part .= ' scope="col"'; 
    125                                                 else if ( $matches[2] == 'r' ) $open_part .= ' scope="row"'; 
     198                                        if ( $matches[2] ) 
     199                                        { 
     200                                                if ( $matches[2] == 'c' ) 
     201                                                { 
     202                                                        $open_part .= ' scope="col"'; 
     203                                                } 
     204                                                else if ( $matches[2] == 'r' ) 
     205                                                { 
     206                                                        $open_part .= ' scope="row"'; 
    126207                                        } 
    127                                 } else { 
     208                                        } 
     209                                } 
     210                                else 
     211                                { 
    128212                                        $trigger_table = 2; 
    129213                                        $open_part .= '<td'; 
    130214                                } 
    131215                                 
    132                                 if ( $matches[3] && $matches[3] > 1 ) $open_part .= ' colspan="'.$matches[3].'"'; 
    133                                 if ( $matches[4] && $matches[4] > 1 ) $open_part .= ' rowspan="'.$matches[4].'"'; 
    134  
     216                                if ( $matches[3] && $matches[3] > 1 ) 
     217                                { 
     218                                        $open_part .= ' colspan="'.$matches[3].'"'; 
     219                                } 
     220 
     221                                if ( $matches[4] && $matches[4] > 1 ) 
     222                                { 
     223                                        $open_part .= ' rowspan="'.$matches[4].'"'; 
     224                                } 
    135225                                $open_part .= '>'; 
    136226                        } 
    137  
    138227                        return $close_part . $open_part; 
     228                } 
     229                else if ( $trigger_table == 1 ) 
     230                { 
     231                        //Are in table, no cell - but not asked to open new: please close and parse again. ;) 
     232                        $close_part = ''; 
     233                        if (2 < $trigger_rowgroup) 
     234                        { 
     235                                $close_part .= '</tbody>'."\n"; 
     236                        } 
     237                        else if (1 < $trigger_rowgroup) 
     238                        { 
     239                                $close_part .= '</tfoot>'."\n"; 
     240                        } 
     241                        else if (0 < $trigger_rowgroup) 
     242                        { 
     243                                $close_part .= '</thead>'."\n"; 
     244                        } 
    139245                         
    140                 } else if ( $trigger_table == 1 ) { 
    141                         //Are in table, no cell - but not asked to open new: please close and parse again. ;) 
    142                         $trigger_table = 0; 
    143                         return "</table>\n".wakka2callback($things); 
     246                        $close_part .= '</table>'."\n"; 
     247                         
     248                        $trigger_table = $trigger_rowgroup = 0; 
     249                         
     250                        return $close_part.wakka2callback($things); 
    144251                } 
    145252                // convert HTML thingies