From 194b3cb387740bc6d8aaa1fb2cbcf4598920e06b Mon Sep 17 00:00:00 2001 From: vargenau Date: Tue, 19 Aug 2008 17:58:25 +0000 Subject: [PATCH] Implement Wikicreole syntax for tables git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@6150 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/plugin/WikicreoleTable.php | 133 +++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 lib/plugin/WikicreoleTable.php diff --git a/lib/plugin/WikicreoleTable.php b/lib/plugin/WikicreoleTable.php new file mode 100644 index 000000000..c987d931b --- /dev/null +++ b/lib/plugin/WikicreoleTable.php @@ -0,0 +1,133 @@ + 1)); + + $lines = preg_split('/\s*?\n\s*/', $argstr); + + foreach ($lines as $line) { + if (!$line) { + continue; + } + $line = trim($line); + // If lines ends with a '|', remove it + if ($line[strlen($line)-1] == '|') { + $line = substr($line, 0, -1); + } + if ($line[0] != '|') { + trigger_error(sprintf(_("Line %s does not begin with a '|'."), $line), E_USER_WARNING); + } else { + $table->pushContent($this->_parse_row($line, $basepage)); + } + } + + return $table; + } + + function _parse_row ($line, $basepage) { + $brkt_link = "\\[ .*? [^]\s] .*? \\]"; + $cell_content = "(?: [^[] | ".ESCAPE_CHAR."\\[ | $brkt_link )*?"; + + preg_match_all("/(\\|+) \s* ($cell_content) \s* (?=\\||\$)/x", + $line, $matches, PREG_SET_ORDER); + + $row = HTML::tr(); + + foreach ($matches as $m) { + $cell = $m[2]; + if ($cell[0] == '=') { + $cell = trim(substr($cell, 1)); + $row->pushContent(HTML::th(TransformInline($cell, 2.0, $basepage))); + } else { + $row->pushContent(HTML::td(TransformInline($cell, 2.0, $basepage))); + } + } + return $row; + } +} + +// $Log: not supported by cvs2svn $ + +// 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: +?> -- 2.45.0