1<?php 2 3class Text_Wiki_Render_Latex_Table extends Text_Wiki_Render { 4 var $cell_id = 0; 5 var $cell_count = 0; 6 var $is_spanning = false; 7 8 var $conf = array( 9 'css_table' => null, 10 'css_tr' => null, 11 'css_th' => null, 12 'css_td' => null 13 ); 14 15 /** 16 * 17 * Renders a token into text matching the requested format. 18 * 19 * @access public 20 * 21 * @param array $options The "options" portion of the token (second 22 * element). 23 * 24 * @return string The text rendered from the token options. 25 * 26 */ 27 28 function token($options) 29 { 30 // make nice variable names (type, attr, span) 31 extract($options); 32 33 switch ($type) 34 { 35 case 'table_start': 36 $this->cell_count = $cols; 37 38 $tbl_start = '\begin{tabular}{|'; 39 for ($a=0; $a < $this->cell_count; $a++) { 40 $tbl_start .= 'l|'; 41 } 42 $tbl_start .= "}\n"; 43 44 return $tbl_start; 45 46 case 'table_end': 47 return "\\hline\n\\end{tabular}\n"; 48 49 case 'caption_start': 50 return "\\caption{"; 51 52 case 'caption_end': 53 return "}\n"; 54 55 case 'row_start': 56 $this->is_spanning = false; 57 $this->cell_id = 0; 58 return "\\hline\n"; 59 60 case 'row_end': 61 return "\\\\\n"; 62 63 case 'cell_start': 64 if ($span > 1) { 65 $col_spec = ''; 66 if ($this->cell_id == 0) { 67 $col_spec = '|'; 68 } 69 $col_spec .= 'l|'; 70 71 $this->cell_id += $span; 72 $this->is_spanning = true; 73 74 return '\multicolumn{' . $span . '}{' . $col_spec . '}{'; 75 } 76 77 $this->cell_id += 1; 78 return ''; 79 80 case 'cell_end': 81 $out = ''; 82 if ($this->is_spanning) { 83 $this->is_spanning = false; 84 $out = '}'; 85 } 86 87 if ($this->cell_id != $this->cell_count) { 88 $out .= ' & '; 89 } 90 91 return $out; 92 93 default: 94 return ''; 95 96 } 97 } 98} 99?> 100