_parse_attr($line); foreach ($attrs as $key => $value) { if (in_array ($key, array("id", "class", "title", "style", "bgcolor", "frame", "rules", "border", "cellspacing", "cellpadding", "summary", "align", "width"))) { $table->setAttr($key, $value); } } } foreach ($lines as $line){ if (substr($line,0,2) == "|}") { // End of table continue; } if (substr($line,0,2) == "|-") { if (isset($row)) { if (isset($cell)) { if (isset($content)) { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); unset($content); } $row->pushContent($cell); unset($cell); } $tbody->pushContent($row); $table->pushContent($tbody); $tbody = HTML::tbody(); } $row = HTML::tr(); $attrs = $this->_parse_attr(substr($line,2)); foreach ($attrs as $key => $value) { if (in_array ($key, array("id", "class", "title", "style", "bgcolor", "align", "valign"))) { $row->setAttr($key, $value); } } continue; } // Table caption if (substr($line,0,2) == "|+") { $caption = HTML::caption(); $line = substr($line,2); $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); if (($pospipe) && ((!$posbracket) || ($posbracket > $pospipe))) { $attrs = $this->_parse_attr(substr($line, 0, $pospipe)); foreach ($attrs as $key => $value) { if (in_array ($key, array("id", "class", "title", "style", "align", "lang"))) { $caption->setAttr($key, $value); } } $line=substr($line, $pospipe+1); } $caption->pushContent(trim($line)); $table->pushContent($caption); } if (((substr($line,0,1) == "|") or (substr($line,0,1) == "!")) and isset($row)) { if (isset($cell)) { if (isset ($content)) { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); unset($content); } $row->pushContent($cell); } if (substr($line,0,1) == "!") { $cell = HTML::th(); // Header $tbody = HTML::thead(); } else { $cell = HTML::td(); $tbody = HTML::tbody(); } $line = substr($line, 1); // If there is a "|" in the line, the start of line // (before the "|") is made of attributes. // The end of the line (after the "|") is the cell content // This is not true if the pipe is inside [] // | [foo|bar] // The following cases must work: // | foo // | [foo|bar] // | class="xxx" | foo // | class="xxx" | [foo|bar] $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); if (($pospipe) && ((!$posbracket) || ($posbracket > $pospipe))) { $attrs = $this->_parse_attr(substr($line, 0, $pospipe)); foreach ($attrs as $key => $value) { if (in_array ($key, array("id", "class", "title", "style", "colspan", "rowspan", "width", "height", "bgcolor", "align", "valign"))) { $cell->setAttr($key, $value); } } $line=substr($line, $pospipe+1); $cell->pushContent(TransformText(trim($line), $markup, $basepage)); continue; } } if (isset($row) and isset($cell)) { $line = str_replace("?\>", "?>", $line); $line = str_replace("\~", "~", $line); if (empty($content)) $content = ''; $content .= $line . "\n"; } } if (isset($row)) { if (isset($cell)) { if (isset($content)) $cell->pushContent(TransformText(trim($content))); $row->pushContent($cell); } $tbody->pushContent($row); $table->pushContent($tbody); } return $table; } function _parse_attr($line) { // We allow attributes with or without quotes (") // border=1, cellpadding="5" // style="font-family: sans-serif; border-top:1px solid #dddddd;" // What will not work is style with comma inside, e. g. // style="font-family: Verdana, Arial, Helvetica, sans-serif" $attr_chunks = preg_split("/\s*,\s*/", strtolower($line)); $options = array(); foreach ($attr_chunks as $attr_pair) { if (empty($attr_pair)) continue; $key_val = preg_split("/\s*=\s*/", $attr_pair); if (!empty($key_val[1])) $options[trim($key_val[0])] = trim(str_replace("\"", "", $key_val[1])); } return $options; } } // $Log: not supported by cvs2svn $ // Revision 1.2 2008/04/04 18:13:49 vargenau // Add tbody to table // // Revision 1.1 2008/01/31 20:40:10 vargenau // Implemented Mediawiki-like syntax for tables // // // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>