| | 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 | */ |
| | 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); |