<?php

namespace FluxBB\Markdown\Node;

use FluxBB\Markdown\Common\Collection;
use FluxBB\Markdown\Common\Text;

class CodeBlock extends Node implements NodeAcceptorInterface
{

    /**
     * @var Collection
     */
    protected $lines;

    /**
     * @var string
     */
    protected $language;


    public function __construct(Text $text, $language = '')
    {
        $this->lines = new Collection([$text]);
        $this->language = $language;
    }

    public function acceptBlankLine(BlankLine $blankLine)
    {
        $this->lines->add($blankLine->getContent()->replace('/^[ ]{0,4}/', ''));

        return $this;
    }

    public function acceptCodeBlock(CodeBlock $codeBlock)
    {
        $codeBlock->lines->each(function (Text $line) {
            $this->lines->add($line);
        });

        return $this;
    }

    public function getContent()
    {
        $content = new Text($this->lines->join("\n"));

        // Just in case we added blank lines at the end, we remove them, and finally add back the trailing newline.
        $content->replace('/(\n[ ]*)*$/', '')->append("\n");

        return $content;
    }

    public function getLines()
    {
        return $this->lines;
    }

    public function hasLanguage()
    {
        return ! empty($this->language);
    }

    public function getLanguage()
    {
        return $this->language;
    }

    public function visit(NodeVisitorInterface $visitor)
    {
        $visitor->visitCodeBlock($this);
    }

}

<?php

namespace FluxBB\Markdown\Node;

use FluxBB\Markdown\Common\Text;

class CodeBlock extends Node implements NodeAcceptorInterface
{

    /**
     * @var Text
     */
    protected $content;

    /**
     * @var string
     */
    protected $language;


    public function __construct(Text $text, $language = '')
    {
        $this->content = $text;
        $this->language = $language;
    }

    public function getContent()
    {
        return $this->content;
    }

    public function hasLanguage()
    {
        return ! empty($this->language);
    }

    public function getLanguage()
    {
        return $this->language;
    }

    public function visit(NodeVisitorInterface $visitor)
    {
        $visitor->visitCodeBlock($this);
    }

}

Simplify code block content storage.
Simplify code block content storage.
