Phosphorum\Markdown\TableExtension::parseBody PHP Method

parseBody() protected method

protected parseBody ( Ciconia\Common\Text $body, Ciconia\Common\Collection $baseTags ) : Ciconia\Common\Collection
$body Ciconia\Common\Text
$baseTags Ciconia\Common\Collection
return Ciconia\Common\Collection
    protected function parseBody(Text $body, Collection $baseTags)
    {
        $rows = new Collection();
        $body->split('/\\n/')->each(function (Text $row, $index) use($baseTags, &$rows) {
            $row->trim()->trim('|');
            $cells = new Collection();
            try {
                $row->split('/\\|/')->each(function (Text $cell, $index) use(&$baseTags, &$cells) {
                    /* @var Tag $tag */
                    $tag = clone $baseTags->get($index);
                    $this->markdown->emit('inline', [$cell]);
                    $tag->setText($cell->trim());
                    $cells->add($tag);
                });
            } catch (\OutOfBoundsException $e) {
                throw new SyntaxError(sprintf('Too much cells on table body (row #%d).', $index), $this, $row, $this->markdown, $e);
            }
            if ($baseTags->count() != $cells->count()) {
                throw new SyntaxError('Unexpected number of table cells in body.', $this, $row, $this->markdown);
            }
            $rows->add($cells);
        });
        return $rows;
    }