Source for file Table.php
Documentation is available at Table.php
// $Id: Table.php,v 1.4 2004/09/25 19:05:13 pmjones Exp $
* This class implements a Text_Wiki_Parse to find source text marked as a
* set of table rows, where a line start and ends with double-pipes (||)
* and uses double-pipes to separate table cells. The rows must be on
* sequential lines (no blank lines between them) -- a blank line
* indicates the beginning of a new table.
* @author Paul M. Jones <pmjones@ciaweb.net>
* The regular expression used to parse the source text and find
* matches conforming to this rule. Used by the parse() method.
var $regex = '/\n((\|\|).*)(\n)(?!(\|\|))/Us';
* Generates a replacement for the matched text.
* 'table_start' : the start of a bullet list
* 'table_end' : the end of a bullet list
* 'row_start' : the start of a number list
* 'row_end' : the end of a number list
* 'cell_start' : the start of item text (bullet or number)
* 'cell_end' : the end of item text (bullet or number)
* 'cols' => the number of columns in the table (for 'table_start')
* 'rows' => the number of rows in the table (for 'table_start')
* 'span' => column span (for 'cell_start')
* 'attr' => column attribute flag (for 'cell_start')
* @param array &$matches The array of matches from parse().
* @return A series of text and delimited tokens marking the different
* table elements and cell text.
// our eventual return value
// the number of columns in the table
// the number of rows in the table
// rows are separated by newlines in the matched text
$rows = explode("\n", $matches[1 ]);
foreach ($rows as $row) {
// increase the row count
$return .= $this->wiki->addToken (
array ('type' => 'row_start')
// cells are separated by double-pipes
// get the number of cells (columns) in this row
$last = count($cell) - 1;
// is this more than the current column count?
// (we decrease by 1 because we never use cell zero)
if ($last - 1 > $num_cols) {
// increase the column count
// by default, cells span only one column (their own)
// ignore cell zero, and ignore the "last" cell; cell zero
// is before the first double-pipe, and the "last" cell is
// after the last double-pipe. both are always empty.
for ($i = 1; $i < $last; $i ++ ) {
// if there is no content at all, then it's an instance
// of two sets of || next to each other, indicating a
// add to the span and loop to the next cell
// this cell has content.
// find any special "attr"ibute cell markers
if (substr($cell[$i], 0 , 2 ) == '> ') {
$cell[$i] = substr($cell[$i], 2 );
} elseif (substr($cell[$i], 0 , 2 ) == '= ') {
$cell[$i] = substr($cell[$i], 2 );
} elseif (substr($cell[$i], 0 , 2 ) == '< ') {
$cell[$i] = substr($cell[$i], 2 );
} elseif (substr($cell[$i], 0 , 2 ) == '~ ') {
$cell[$i] = substr($cell[$i], 2 );
$return .= $this->wiki->addToken (
$return .= trim($cell[$i]);
$return .= $this->wiki->addToken (
$return .= $this->wiki->addToken (
array ('type' => 'row_end')
// wrap the return value in start and end tokens
Documentation generated on Mon, 11 Mar 2019 14:22:34 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|