Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 172 → Rev 173

/trunk/api/text/wiki_wikini/Parse/Table.php
1,5 → 1,5
<?php
// $Id: Table.php,v 1.1 2004-11-24 19:43:09 jpm Exp $
// $Id: Table.php,v 1.2 2004-11-25 15:36:19 jpm Exp $
 
 
/**
32,7 → 32,7
*
*/
var $regex = '/\n((\[\|).+?)(\|\])/ms';
var $regex = '/\n(\[\|(.*)\n)(.+)(\n\|\])/Ums';
/**
78,7 → 78,7
$num_rows = 0;
// rows are separated by newlines in the matched text
$rows = explode("\n", $matches[1]);
$rows = explode("\n", $matches[3]);
// loop through each row
foreach ($rows as $row) {
86,12 → 86,6
// increase the row count
$num_rows ++;
// start a new row
$return .= $this->wiki->addToken(
$this->rule,
array('type' => 'row_start')
);
// cells are separated by double-pipes
$cell = explode("|", $row);
105,9 → 99,21
$num_cols = $last - 1;
}
// by default, cells span only one column (their own)
$span = 1;
// Les attributs de la ligne
if (preg_match('/^!(.*)!$/U', $cell[0], $morceaux)) {
$attr = $morceaux[1];
} else {
$attr = '';
}
// start a new row
$return .= $this->wiki->addToken(
$this->rule,
array( 'type' => 'row_start',
'attr' => $attr,
'span' => 1)
);
// 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.
116,35 → 122,33
// of two sets of || next to each other, indicating a
// span.
if ($cell[$i] == '') {
// add to the span and loop to the next cell
$span += 1;
continue;
} else {
// this cell has content.
// find any special "attr"ibute cell markers
if (substr($cell[$i], 0, 2) == '> ') {
if (substr($cell[$i], 0, 1) == ' ' && substr($cell[$i], -1, 1) != ' ') {
// right-align
$attr = 'right';
$cell[$i] = substr($cell[$i], 2);
} elseif (substr($cell[$i], 0, 2) == '= ') {
$attr = 'align="right"';
$cell[$i] = substr($cell[$i], 1);
} elseif (substr($cell[$i], 0, 1) == ' ' && substr($cell[$i], -1, 1) == ' ') {
// center-align
$attr = 'center';
$cell[$i] = substr($cell[$i], 2);
} elseif (substr($cell[$i], 0, 2) == '< ') {
$attr = 'align="center"';
$cell[$i] = substr(substr($cell[$i], 1), 0, -1);
} elseif (substr($cell[$i], 0, 1) != ' ' && substr($cell[$i], -1, 1) == ' ') {
// left-align
$attr = 'left';
$cell[$i] = substr($cell[$i], 2);
} elseif (substr($cell[$i], 0, 2) == '~ ') {
$attr = 'header';
$cell[$i] = substr($cell[$i], 2);
$attr = 'align="left"';
$cell[$i] = substr($cell[$i], 0, -1);
} else {
$attr = null;
}
if (substr($cell[$i], 0, 1) == '!') {
// Les attributs de la cellule
preg_match('/^!(.*)!(.*)$/U', $cell[$i], $morceaux);
$attr .= ' '.$morceaux[1];
$cell[$i] = $morceaux[2];
}
// start a new cell...
$return .= $this->wiki->addToken(
$this->rule,
151,8 → 155,9
array (
'type' => 'cell_start',
'attr' => $attr,
'span' => $span
)
'span' => 1
),
false
);
// ...add the content...
163,15 → 168,11
$this->rule,
array (
'type' => 'cell_end',
'attr' => $attr,
'span' => $span
)
'attr' => $attr
),
false
);
// reset the span.
$span = 1;
}
}
// end the row
189,7 → 190,8
array(
'type' => 'table_start',
'rows' => $num_rows,
'cols' => $num_cols
'cols' => $num_cols,
'attr' => $matches[2]
)
)
. $return .