Changeset 129

Show
Ignore:
Timestamp:
06/16/2006 05:48:55 AM (4 years ago)
Author:
DarTar
Message:

Adding formatter support for simple table markup. Credits: Tormod Haugen - #230

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/css/wikka.css

    r126 r129  
    439439/* Action-related styling */ 
    440440 
    441 /* Table action */ 
     441/* Tables */ 
    442442 
    443443table.wikka { 
     
    445445        border-collapse: collapse; 
    446446        border-spacing: 0; 
     447} 
     448 
     449table.wikka caption{ 
     450        border: 1px dotted #BBB; 
     451        font-size: 90%; 
     452        color: #666; 
     453        margin:5px 0; 
     454        padding:2px; 
     455} 
     456 
     457table.wikka th { 
     458        border: 1px solid #CCC; 
     459        padding: .1em .25em; 
     460        background-color: #EEE; 
    447461} 
    448462 
  • trunk/formatters/wakka.php

    r122 r129  
    11<?php 
     2/** 
     3 * Wikka Formatting Engine 
     4 *  
     5 * This is the main formatting engine used by Wikka to parse wiki markup and render valid XHTML. 
     6 *  
     7 * @package Formatters 
     8 * @name Wakka 
     9 * 
     10 * @author {@link http://wikkawiki.org/JsnX Jason Tourtelotte} 
     11 * @author {@link http://wikkawiki.org/DotMG Mahefa Randimbisoa} 
     12 * @author {@link http://wikkawiki.org/JavaWoman Marjolein Katsma} 
     13 * @author {@link http://wikkawiki.org/NilsLindenberg Nils Lindenberg} (code cleanup) 
     14 * @author {@link http://wikkawiki.org/DarTar Dario Taraborelli} (grab handler and filename support for codeblocks) 
     15 * @author {@link http://wikkawiki.org/TormodHaugen Tormod Haugen} (table formatter support) 
     16 *  
     17 * @todo                - add support for formatter plugins; 
     18 *                      - use a central RegEx library #34; 
     19 */ 
    220 
    321// i18n strings 
     
    2745                static $newIndentSpace= array(); 
    2846                static $br = 1; 
     47                static $trigger_table = 0; 
    2948                static $trigger_bold = 0; 
    3049                static $trigger_italic = 0; 
     
    4968                if ((!is_array($things)) && ($things == 'closetags')) 
    5069                { 
     70                        if (2 < $trigger_table) echo ('</th></tr>'); 
     71                        else if (1 < $trigger_table) echo ('</td></tr>'); 
     72                        if (0 < $trigger_table) echo ('</table>'); 
    5173                        if ($trigger_strike % 2) echo ('</span>'); 
    5274                        if ($trigger_notes % 2) echo ('</span>'); 
     
    6082                        for ($i = 1; $i<=5; $i ++) 
    6183                                if ($trigger_l[$i] % 2) echo ("</h$i>"); 
    62                         $trigger_bold = $trigger_center = $trigger_floatl = $trigger_inserted = $trigger_deleted = $trigger_italic = $trigger_keys = 0; 
     84                        $trigger_bold = $trigger_center = $trigger_floatl = $trigger_inserted = $trigger_deleted = $trigger_italic = $trigger_keys = $trigger_table = 0; 
    6385                        $trigger_l = array(-1, 0, 0, 0, 0, 0); 
    6486                        $trigger_monospace = $trigger_notes = $trigger_strike = $trigger_underline = 0; 
    6587                        return; 
     88                } 
     89                if ( preg_match("/^\|(\?)(.*?)?\|(\n)?$/", $thing, $matches) ) { 
     90                        if ( $trigger_table == 0 ) { 
     91                                $trigger_table = 1; 
     92                                //TODO escape text for safety 
     93                                return '<table class="wikka" summary="'.$matches[2].'">'."\n"; 
     94                        } 
     95                } 
     96                // 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("/^\|(=|!)?(\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 == 0 ) 
     100                        { 
     101                                $rs = "<table class=\"wikka\">\n"; 
     102                                if ($matches[1] == "!") { 
     103                                        $trigger_table = 4; 
     104                                        return $rs."<caption>"; 
     105                                } else { 
     106                                        $rs .= "<tr>"; 
     107                                } 
     108                        } 
     109                        else if ( $trigger_table == 1 ) { 
     110                                if ($matches[1] == "!") { 
     111                                        $trigger_table = 4; 
     112                                        return "<caption>"; 
     113                                } else { 
     114                                        $rs = "<tr>"; 
     115                                } 
     116                        } 
     117                        else if ( $trigger_table == 2 ) $rs = "</td>"; 
     118                        else if ( $trigger_table == 3 ) $rs = "</th>"; 
     119                        else if ( $trigger_table == 4 ) { 
     120                                $trigger_table = 1; 
     121                                return "</caption>\n"; 
     122                        } 
     123                         
     124                        if ( $trigger_table > 1 && $matches[4] == "\n") { 
     125                                $trigger_table = 1; 
     126                                return $rs."</tr>\n"; 
     127                        } 
     128                         
     129                        if ( $matches[1] == "=" ) { 
     130                                $trigger_table = 3; 
     131                                $rs .= "<th"; 
     132                        } else if ( $matches[1] == "" ) { 
     133                                $trigger_table = 2; 
     134                                $rs .= "<td"; 
     135                        } 
     136                        if ( $matches[2] && $matches[2] > 1 ) $rs .= " colspan=\"$matches[2]\""; 
     137                        if ( $matches[3] && $matches[3] > 1 ) $rs .= " rowspan=\"$matches[3]\""; 
     138                         
     139                        return $rs.">"; 
     140 
     141                } else if ( $trigger_table == 1 ) { 
     142                        //Are in table, no cell - but not asked to open new: please close and parse again. ;) 
     143                        $trigger_table = 0; 
     144                        return "</table>\n".wakka2callback($things); 
    66145                } 
    67146                // convert HTML thingies 
     
    415494        "======|=====|====|===|==|".                                                                                                                    # headings 
    416495        "\n([\t~]+)(-|&|[0-9a-zA-Z]+\))?|".                                                                                                             # indents and lists 
     496        "\|[^\|]*?\|(?:\n)?|".                                                                                                                                  # Simple Tables  
    417497        "\{\{.*?\}\}|".                                                                                                                                                 # action 
    418498        "\b[A-ZÄÖÜ][A-Za-zÄÖÜßäöü]+[:](?![=_])\S*\b|".                                                                                  # InterWiki link