* Jeff |< Dairiki |^ Cheap |< Not worth it * |> Marco |< Polo | Cheaper |< Not available * ?> * * * Note that multiple |'s lead to spanned columns, * and v's can be used to span rows. A > * generates a right justified column, < a left * justified column and ^ a centered column * (which is the default.) * * @author Geoffrey T. Dairiki */ class WikiPlugin_OldStyleTable extends WikiPlugin { function getName() { return _("OldStyleTable"); } function getDescription() { return _("Layout tables using the old markup style."); } function getVersion() { return preg_replace("/[Revision: $]/", '', "\$Revision: 1.6 $"); } function getDefaultArguments() { return array(); } function run($dbi, $argstr, $request) { global $Theme; include_once('lib/InlineParser.php'); $lines = preg_split('/\s*?\n\s*/', $argstr); $table = HTML::table(array('cellpadding' => 1, 'cellspacing' => 1, 'border' => 1)); foreach ($lines as $line) { if (!$line) continue; if ($line[0] != '|') return $this->error(fmt("Line does not begin with a '|'.")); $table->pushContent($this->_parse_row($line)); } return $table; } function _parse_row ($line) { preg_match_all('/(\|+)(v*)([<>^]?)\s*(.*?)\s*(?=\||$)/', $line, $matches, PREG_SET_ORDER); $row = HTML::tr(); foreach ($matches as $m) { $attr = array(); if (strlen($m[1]) > 1) $attr['colspan'] = strlen($m[1]); if (strlen($m[2]) > 0) $attr['rowspan'] = strlen($m[2]) + 1; if ($m[3] == '^') $attr['align'] = 'center'; else if ($m[3] == '>') $attr['align'] = 'right'; else $attr['align'] = 'left'; // Assume new-style inline markup. $content = TransformInline($m[4]); $row->pushContent(HTML::td($attr, HTML::raw(' '), $content, HTML::raw(' '))); } return $row; } }; // $Log: not supported by cvs2svn $ // Revision 1.5 2003/01/18 21:48:59 carstenklapp // Code cleanup: // Reformatting & tabs to spaces; // Added copyleft, getVersion, getDescription, rcs_id. // // (c-file-style: "gnu") // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>