<?php

namespace FluxBB\Markdown\Node;

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

class Paragraph extends Node implements NodeAcceptorInterface
{

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


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

    public function getText()
    {
        return (new Text($this->lines->apply(function (Text $line) {
            return $line->copy()->ltrim();
        })->join("\n")))->trim();
    }

    public function acceptParagraph(Paragraph $paragraph)
    {
        $paragraph->lines->each(function (Text $line) {
            $this->lines->add($line);
        });

        return $this;
    }

    public function acceptBlankLine(BlankLine $blankLine)
    {
        return $this->parent;
    }

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

        return $this;
    }

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

        $visitor->leaveParagraph($this);
    }

}

<?php

namespace FluxBB\Markdown\Node;

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

class Paragraph extends Node implements NodeAcceptorInterface
{

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


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

    public function getText()
    {
        return (new Text($this->lines->join("\n")))->trim();
    }

    public function acceptParagraph(Paragraph $paragraph)
    {
        $paragraph->lines->each(function (Text $line) {
            $this->lines->add($line);
        });

        return $this;
    }

    public function acceptBlankLine(BlankLine $blankLine)
    {
        return $this->parent;
    }

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

        return $this;
    }

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

        $visitor->leaveParagraph($this);
    }

}

--- 
+++ 
@@ -21,7 +21,9 @@
 
     public function getText()
     {
-        return (new Text($this->lines->join("\n")))->trim();
+        return (new Text($this->lines->apply(function (Text $line) {
+            return $line->copy()->ltrim();
+        })->join("\n")))->trim();
     }
 
     public function acceptParagraph(Paragraph $paragraph)
Trim beginning of every line in a paragraph.
