Пример #1
0
function parse_table($text)
{
    global $page;
    static $in_table = false;
    static $table_count = 0;
    $pre = '';
    $post = '';
    $csv_download = false;
    if (preg_match('/^\\*?(\\|\\|)+.*(\\|\\|)\\s*$/', $text)) {
        if (!$in_table) {
            $pre = html_table_start();
            $in_table = true;
            $table_count++;
            if (preg_match('/^\\*(\\|\\|)+.*(\\|\\|)\\s*$/', $text)) {
                $csv_download = true;
            }
        }
        $text = preg_replace('/^\\*?((\\|\\|)+)(.*)\\|\\|\\s*$/e', "new_entity(array('raw',html_table_row_start().html_table_cell_start(strlen('\\1')/2)))." . "q1('\\3').new_entity(array('raw',html_table_cell_end().html_table_row_end()))", $text, -1);
        $text = preg_replace('/((\\|\\|)+)/e', "new_entity(array('raw',html_table_cell_end().html_table_cell_start(strlen('\\1')/2)))", $text, -1);
    } else {
        if ($in_table) {
            $in_table = false;
            $pre = html_table_end();
        }
    }
    if ($pre != '') {
        $text = new_entity(array('raw', $pre)) . parse_newline($text);
        if ($csv_download) {
            $img = '<img align="top" src="images/csv.png" alt="Download as CSV" ' . 'title="Download as CSV" hspace="3" width="14" height="15" ' . 'border="0">';
            $text = html_table_start() . html_table_row_start() . html_table_cell_start() . '<a href="' . tablecsvURL($page, $table_count) . '">' . $img . '<small>Download as CSV</small></a>' . html_table_cell_end() . html_table_row_end() . html_table_end() . $text;
        }
    }
    if ($post != '') {
        $text = $text . new_entity(array('raw', $post));
    }
    return $text;
}
function parse_table($text)
{
    static $in_table = 0;
    $pre = '';
    $post = '';
    if (preg_match('/^(\\|\\|)+.*(\\|\\|)\\s*$/', $text)) {
        if (!$in_table) {
            $pre = html_table_start();
            $in_table = 1;
        }
        $text = preg_replace('/^((\\|\\|)+)(.*)\\|\\|\\s*$/e', "new_entity(array('raw',html_table_row_start().html_table_cell_start(strlen('\\1')/2)))." . "q1('\\3').new_entity(array('raw',html_table_cell_end().html_table_row_end()))", $text, -1);
        $text = preg_replace('/((\\|\\|)+)/e', "new_entity(array('raw',html_table_cell_end().html_table_cell_start(strlen('\\1')/2)))", $text, -1);
    } else {
        if ($in_table) {
            $in_table = 0;
            $pre = html_table_end();
        }
    }
    if ($pre != '') {
        $text = new_entity(array('raw', $pre)) . $text;
    }
    if ($post != '') {
        $text = $text . new_entity(array('raw', $post));
    }
    return $text;
}
Пример #3
0
function parse_table($text)
{
    static $in_table = 0;
    $pre = '';
    $post = '';
    if (preg_match('/^(\\|\\|)+(\\{([^{}]+)\\})?.*(\\|\\|)\\s*$/', $text, $args)) {
        if (!$in_table) {
            $pre = html_table_start($args[3]);
            $in_table = 1;
        }
        $text = preg_replace('/\\|\\s+\\|/e', "q1('|').new_entity(array('raw','&nbsp;')).q1('|')", $text);
        $text = preg_replace('/^((\\|\\|+)(\\{([^{}]+)\\})?)(.*)\\|\\|\\s*$/e', "new_entity(array('raw',html_table_row_start('\\4').\r\n                                                 html_table_cell_start(strlen('\\2')/2, '\\4')))." . "q1('\\5').new_entity(array('raw',html_table_cell_end().html_table_row_end()))", $text, -1);
        $text = preg_replace('/((\\|\\|+)(\\{([^{}]+)\\})?)/e', "new_entity(array('raw',html_table_cell_end().html_table_cell_start(strlen('\\2')/2, '\\4')))", $text, -1);
    } else {
        if ($in_table) {
            $in_table = 0;
            $pre = html_table_end();
        }
    }
    if ($pre != '') {
        $text = new_entity(array('raw', $pre)) . $text;
    }
    if ($post != '') {
        $text = $text . new_entity(array('raw', $post));
    }
    return $text;
}