protected function consumeTable($lines, $current)
	{
		// consume until newline

		$block = [
			'table',
			'cols' => [],
			'rows' => [],
		];
		for ($i = $current, $count = count($lines); $i < $count; $i++) {
			$line = trim($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 === '' || substr($lines[$i], 0, 4) === '    ') {
				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);
			}

			array_unshift($this->context, 'table');
			$row = $this->parseInline($line);
			array_shift($this->context);

			$r = count($block['rows']);
			$c = 0;
			$block['rows'][] = [];
			foreach ($row as $absy) {
				if (!isset($block['rows'][$r][$c])) {
					$block['rows'][$r][] = [];
				}
				if ($absy[0] === 'tableBoundary') {
					$c++;
				} else {
					$block['rows'][$r][$c][] = $absy;
				}
			}
		}

		return [$block, --$i];
	}
protected function consumeTable($lines, $current)
	{
		// consume until newline

		$block = [
			'table',
			'cols' => [],
			'rows' => [],
		];
		for ($i = $current, $count = count($lines); $i < $count; $i++) {
			$line = trim($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 === '' || substr($lines[$i], 0, 4) === '    ') {
				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);
			}

			array_unshift($this->context, 'table');
			$row = $this->parseInline($line);
			array_shift($this->context);

			$r = count($block['rows']);
			$c = 0;
			$block['rows'][] = [];
			foreach ($row as $absy) {
				if (!isset($block['rows'][$r][$c])) {
					$block['rows'][$r][] = [];
				}
				if ($absy[0] === 'tableBoundary') {
					$c++;
				} else {
					$block['rows'][$r][$c][] = $absy;
				}
			}
		}

		return [$block, --$i];
	}
protected function consumeTable ( $ lines , $ current ) { // consume until newline $ block = [ 'table' , 'cols' => [ ] , 'rows' => [ ] , ] ; for ( $ i = $ current , $ count = count ( $ lines ) ; $ i < $ count ; $ i ++ ) { $ line = trim ( $ 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 === '' || substr ( $ lines [ $ i ] , 0 , 4 ) === '    ' ) { 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 ) ; } array_unshift ( $ this -> context , 'table' ) ; $ row = $ this -> parseInline ( $ line ) ; array_shift ( $ this -> context ) ; $ r = count ( $ block [ 'rows' ] ) ; $ c = 0 ; $ block [ 'rows' ] [ ] = [ ] ; foreach ( $ row as $ absy ) { if ( ! isset ( $ block [ 'rows' ] [ $ r ] [ $ c ] ) ) { $ block [ 'rows' ] [ $ r ] [ ] = [ ] ; } if ( $ absy [ 0 ] === 'tableBoundary' ) { $ c ++ ; } else { $ block [ 'rows' ] [ $ r ] [ $ c ] [ ] = $ absy ; } } } return [ $ block , -- $ i ] ; }
Consume lines for a table
Consume lines for a table