From: Carsten K. <car...@us...> - 2003-12-05 20:41:47
|
On Thursday, December 4, 2003, at 09:25 am, Reini Urban wrote: > The attached diff is better. > It supports summary also, has no linebreaks and > it also includes the new pgsrc of the description page. Hi, Thanks you two, for working on this! I applied the second patch to htdocs/phpwiki2/lib/plugin/OldStyleTable.php for testing. Only one problem, the caption does not show. :/ http://phpwiki.sourceforge.net/phpwiki/OldStyleTablePlugin I found the bug: caption is not an attribute of <table>, rather it must be the first sub-element (if present). So it should be like this: <table summary="summary"> <caption>Table caption</caption> <tr><td>first row</td></tr> http://www.w3.org/TR/1999/REC-html401-19991224/struct/tables.html Cheers, Carsten Here's the updated patch: (some of it is text reformatting) Index: OldStyleTable.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/OldStyleTable.php,v retrieving revision 1.7 diff -U2 -r1.7 OldStyleTable.php --- OldStyleTable.php 21 Feb 2003 23:00:35 -0000 1.7 +++ OldStyleTable.php 5 Dec 2003 20:37:28 -0000 @@ -1,4 +1,5 @@ <?php // -*-php-*- rcs_id('$Id: OldStyleTable.php,v 1.7 2003/02/21 23:00:35 dairiki Exp $'); + /** Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam @@ -26,5 +27,5 @@ * Usage: * <pre> - * <?plugin OldStyleTable + * <?plugin OldStyleTable border||=0 summary="" * || __Name__ |v __Cost__ |v __Notes__ * | __First__ | __Last__ @@ -51,5 +52,5 @@ function getDescription() { - return _("Layout tables using the old markup style."); + return _("Layout tables using the old markup style."); } @@ -60,5 +61,15 @@ function getDefaultArguments() { - return array(); + return array( + 'caption' => '', + 'cellpadding' => '1', + 'cellspacing' => '1', + 'border' => '1', + 'summary' => '', + ); + } + + function handle_plugin_args_cruft($argstr, $args) { + return; } @@ -67,12 +78,33 @@ include_once('lib/InlineParser.php'); + $args = $this->getArgs($argstr, $request); + $default = $this->getDefaultArguments(); + foreach (array('cellpadding', 'cellspacing', 'border') as $arg) { + if (!is_numeric($args[$arg])) { + $args[$arg] = $default[$arg]; + } + } $lines = preg_split('/\s*?\n\s*/', $argstr); - $table = HTML::table(array('cellpadding' => 1, - 'cellspacing' => 1, - 'border' => 1)); + $table_args = array(); + $default_args = array_keys($default); + foreach ($default_args as $arg) { + if ($args[$arg] == '' and $default[$arg] == '') + continue; // ignore '' arguments + $table_args[$arg] = $args[$arg]; + } + unset($table_args['caption']); + $table = HTML::table($table_args); + if ($caption = $args['caption']) { + $table->pushContent(HTML::caption(array('align'=>'top'), $caption)); + } foreach ($lines as $line) { if (!$line) continue; + if (strstr($line, "=")) { + $tmp = explode("=", $line); + if (in_array(trim($tmp[0]), $default_args)) + continue; + } if ($line[0] != '|') return $this->error(fmt("Line does not begin with a '|'.")); @@ -85,6 +117,5 @@ function _parse_row ($line, $basepage) { $brkt_link = "\\[ .*? [^]\s] .*? \\]"; - $cell_content = "(?: [^[] | ".ESCAPE_CHAR."\\[ | $brkt_link )*?"; - + $cell_content = "(?: [^[] | " . ESCAPE_CHAR . "\\[ | $brkt_link )*?"; preg_match_all("/(\\|+) (v*) ([<>^]?) \s* ($cell_content) \s* (?=\\||\$)/x", $line, $matches, PREG_SET_ORDER); @@ -116,4 +147,8 @@ } }; + +// Caption & summary patch from [phpwiki-talk] by MickiKaufman and +// ReiniUrban 2003-12-04. Not yet checked into CVS. + // $Log: OldStyleTable.php,v $ |