public function render(bool $trim = false): string
    {
        $this->output = '';

        $block_open = false;

        foreach ($this->deltas as $i => $delta) {
            if (
                $delta->displayType() === Delta::DISPLAY_INLINE &&
                $block_open === false
            ) {
                $block_open = true;
                $this->output .= '<p>';
            }

            if ($delta->isChild() === true && $delta->isFirstChild() === true) {

                if (
                    $block_open === true &&
                    $this->deltas[$i - 1]->displayType() === Delta::DISPLAY_INLINE
                ) {
                    $this->output .= "</p>\n";
                    $block_open = false;
                }

                $this->output .= '<' . $delta->parentTag() . ">\n";
            }

            if (
                $delta->displayType() === Delta::DISPLAY_BLOCK &&
                $block_open === true
            ) {
                $block_open = false;
                $this->output .= "</p>\n";
            }

            $this->output .= $delta->render();

            if (
                $delta->displayType() === Delta::DISPLAY_INLINE &&
                (
                    $block_open === true &&
                    $delta->close() === true
                )
            ) {
                $this->output .= "</p>\n";
                $block_open = false;
            }

            if ($delta->isChild() === true && $delta->isLastChild() === true) {
                $this->output .= '</' . $delta->parentTag() . ">\n";
            }

            if (
                $i === count($this->deltas) - 1 &&
                $delta->displayType() === Delta::DISPLAY_INLINE && $block_open === true
            ) {
                $this->output .= "</p>\n";
            }
        }

        if ($trim === false) {
            return $this->output;
        } else {
            return trim($this->output);
        }
    }