Source for file table.php
Documentation is available at table.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pmjones@ciaweb.net> |
// +----------------------------------------------------------------------+
// $Id: table.php,v 1.2 2004/03/27 14:47:32 pmjones Exp $
* This class implements a Text_Wiki_Rule 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. Token options are:
* '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)
* 'colspan' => column span (for a cell)
* @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.
// out eventual return value
$return .= $this->addToken(array ('type' => 'table_start'));
// rows are separated by newlines in the matched text
$rows = explode("\n", $matches[1 ]);
foreach ($rows as $row) {
$return .= $this->addToken(array ('type' => 'row_start'));
// cells are separated by double-pipes
// get the last cell number
$last = count($cell) - 1;
// 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 the alignment, if any.
if (substr($cell[$i], 0 , 2 ) == '> ') {
// set to right-align and strip the tag
$cell[$i] = substr($cell[$i], 2 );
} elseif (substr($cell[$i], 0 , 2 ) == '= ') {
// set to center-align and strip the tag
$cell[$i] = substr($cell[$i], 2 );
} elseif (substr($cell[$i], 0 , 2 ) == '< ') {
// set to left-align and strip the tag
$cell[$i] = substr($cell[$i], 2 );
$return .= trim($cell[$i]);
$return .= $this->addToken(array ('type' => 'row_end'));
$return .= $this->addToken(array ('type' => 'table_end'));
* Renders a token into text matching the requested format.
* @param array $options The "options" portion of the token (second
* @return string The text rendered from the token options.
// make nice variable names (type, align, colspan)
$border = (isset ($this->_conf['border']))
? $this->_conf['border'] : '1';
$spacing = (isset ($this->_conf['spacing']))
? $this->_conf['spacing'] : '0';
$padding = (isset ($this->_conf['padding']))
? $this->_conf['padding'] : '4';
return " <table border=\"$border\" " .
" cellspacing=\"$spacing\" " .
" cellpadding=\"$padding\">\n";
$tmp = $pad . $pad . '<td';
$tmp .= " colspan=\"$colspan\"";
$tmp .= " align=\"$align\"";
Documentation generated on Mon, 11 Mar 2019 10:14:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|