[],
'rows' => [],
];
$beginsWithPipe = $lines[$current][0] === '|';
for ($i = $current, $count = count($lines); $i < $count; $i++) {
$line = rtrim($lines[$i]);
// extract alignment from second line
if ($i == $current+1) {
$cols = explode('|', trim($line, ' |'));
foreach($cols as $col) {
$col = trim($col);
if (empty($col)) {
$block['cols'][] = '';
continue;
}
$l = ($col[0] === ':');
$r = (substr($col, -1, 1) === ':');
if ($l && $r) {
$block['cols'][] = 'center';
} elseif ($l) {
$block['cols'][] = 'left';
} elseif ($r) {
$block['cols'][] = 'right';
} else {
$block['cols'][] = '';
}
}
continue;
}
if ($line === '' || $beginsWithPipe && $line[0] !== '|') {
break;
}
if ($line[0] === '|') {
$line = substr($line, 1);
}
if (substr($line, -1, 1) === '|' && (substr($line, -2, 2) !== '\\|' || substr($line, -3, 3) === '\\\\|')) {
$line = substr($line, 0, -1);
}
$block['rows'][] = $line;
}
return [$block, --$i];
}
/**
* render a table block
*/
protected function renderTable($block)
{
$content = '';
$this->_tableCellAlign = $block['cols'];
$content .= "\n";
$first = true;
foreach($block['rows'] as $row) {
$this->_tableCellTag = $first ? 'th' : 'td';
$align = empty($this->_tableCellAlign[$this->_tableCellCount]) ? '' : ' align="' . $this->_tableCellAlign[$this->_tableCellCount++] . '"';
$tds = "<$this->_tableCellTag$align>" . trim($this->renderAbsy($this->parseInline($row))) . "$this->_tableCellTag>"; // TODO move this to the consume step
$content .= "$tds \n";
if ($first) {
$content .= "\n