Table.php 2.41 KB
Newer Older
zYne's avatar
zYne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
<?php

class Text_Wiki_Render_Latex_Table extends Text_Wiki_Render {
    var $cell_id    = 0;
    var $cell_count = 0;
    var $is_spanning = false;

    var $conf = array(
                      'css_table' => null,
                      'css_tr' => null,
                      'css_th' => null,
                      'css_td' => null
                      );

    /**
     *
     * Renders a token into text matching the requested format.
     *
     * @access public
     *
     * @param array $options The "options" portion of the token (second
     * element).
     *
     * @return string The text rendered from the token options.
     *
     */

    function token($options)
    {
        // make nice variable names (type, attr, span)
        extract($options);

        switch ($type)
            {
            case 'table_start':
                $this->cell_count = $cols;

                $tbl_start = '\begin{tabular}{|';
                for ($a=0; $a < $this->cell_count; $a++) {
                    $tbl_start .= 'l|';
                }
                $tbl_start .= "}\n";

                return $tbl_start;

            case 'table_end':
                return "\\hline\n\\end{tabular}\n";

            case 'caption_start':
                return "\\caption{";

            case 'caption_end':
                return "}\n";

            case 'row_start':
                $this->is_spanning = false;
                $this->cell_id = 0;
                return "\\hline\n";

            case 'row_end':
                return "\\\\\n";

            case 'cell_start':
                if ($span > 1) {
                    $col_spec = '';
                    if ($this->cell_id == 0) {
                        $col_spec = '|';
                    }
                    $col_spec .= 'l|';

                    $this->cell_id += $span;
                    $this->is_spanning = true;

                    return '\multicolumn{' . $span . '}{' . $col_spec . '}{';
                }

                $this->cell_id += 1;
                return '';

            case 'cell_end':
                $out = '';
                if ($this->is_spanning) {
                    $this->is_spanning = false;
                    $out = '}';
                }

                if ($this->cell_id != $this->cell_count) {
                    $out .= ' & ';
                }

                return $out;

            default:
                return '';

            }
    }
}
?>