cvs: pear /Text_Wiki/Text/Wiki/Parse/Mediawiki Table.php
| From: | bertrand GUGGER | Date: | Mon, 15 Aug 2005 18:34:54 +0000 |
| Subject: | cvs: pear /Text_Wiki/Text/Wiki/Parse/Mediawiki Table.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-33990@lists.php.net to get a copy of this message | ||
toggg Mon Aug 15 14:34:54 2005 EDT
Modified files:
/pear/Text_Wiki/Text/Wiki/Parse/Mediawiki Table.php
Log:
Rowspan, colspan and avoid empty cells
http://cvs.php.net/diff.php/pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Table.php?r1=1.4&r2=1.5&ty=u
Index: pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Table.php
diff -u pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Table.php:1.4
pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Table.php:1.5
--- pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Table.php:1.4 Mon Aug 15 01:28:07 2005
+++ pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Table.php Mon Aug 15 14:34:53 2005
@@ -15,7 +15,7 @@
* @author Bertrand Gugger <bertrand@toggg.com>
* @copyright 2005 bertrand Gugger
* @license http://www.gnu.org/copyleft/lesser.html LGPL
License 2.1
- * @version CVS: $Id: Table.php,v 1.4 2005/08/15 05:28:07 toggg Exp $
+ * @version CVS: $Id: Table.php,v 1.5 2005/08/15 18:34:53 toggg Exp $
* @link http://pear.php.net/package/Text_Wiki
*/
@@ -64,7 +64,7 @@
* @see processCells()
*/
var $regexCells =
- '#((?:^\||^!|\|\||!!|\G))( [^|\n]*? \|(?!\|))?(.*?)(?=^\||^!|\|\||!!|\z)#msi';
+ '#((?:^\||^!|\|\||!!|\G))(?:( [^|\n]*?) \|(?!\|))?(.+?)(?=^\||^!|\|\||!!|\z)#msi';
/**
* The current table nesting depth, starts by zero
@@ -99,12 +99,12 @@
var $_countCells = array();
/**
- * The type of table for this level ('bullet' or 'number')
+ * The count of spanned cells from previous rowspans for each column
*
* @access private
- * @var int
- var $_type = array();
+ * @var array of int
*/
+ var $_spanCells = array();
/**
* Generates a replacement for the matched text. Returned token options are:
@@ -152,7 +152,7 @@
$expsub = $matches[3];
}
$this->_countRows[$this->_level] = $this->_maxCells[$this->_level] = 0;
- $this->_countCells[$this->_level] = array();
+ $this->_countCells[$this->_level] = $this->_spanCells[$this->_level] = array();
$sub = preg_replace_callback(
$this->regexRows,
array(&$this, 'processRows'),
@@ -251,15 +251,33 @@
*/
function processCells(&$matches)
{//var_dump($matches);echo '<br />';
+ $order = &
$this->_countCells[$this->_level][$this->_countRows[$this->_level]];
+ while (isset($this->_spanCells[$this->_level][$order])) {
+ if (--$this->_spanCells[$this->_level][$order] < 2) {
+ unset($this->_spanCells[$this->_level][$order]);
+ }
+ $order++;
+ }
$param = array(
'type' => 'cell_start',
'attr' => $matches[1] && ($matches[1]{0} == '!') ?
'header': null,
'span' => 1,
- 'order' =>
$this->_countCells[$this->_level][$this->_countRows[$this->_level]]++
+ 'rowspan' => 1,
+ 'order' => $order
);
if ($format = trim($matches[2])) {
+ if (preg_match('#(.*)colspan=("|\')?(\d+)\2(.*)#i', $format,
$pieces)) {
+ $param['span'] = (int)$pieces[3];
+ $format = $pieces[1] . $pieces[4];
+ }
+ if (preg_match('#(.*)rowspan=("|\')?(\d+)\2(.*)#i', $format,
$pieces)) {
+ $this->_spanCells[$this->_level][$order] =
+ $param['rowspan'] = (int)$pieces[3];
+ $format = $pieces[1] . $pieces[4];
+ }
$param['format'] = $format;
}
+ $this->_countCells[$this->_level][$this->_countRows[$this->_level]] +=
$param['span'];
$ret = $this->wiki->addToken($this->rule, $param );
$param['type'] = 'cell_end';
return $ret . $matches[3] . $this->wiki->addToken($this->rule, $param );