Markdownify\Converter::out PHP Method

out() protected method

append string to the correct var, either directly to $this->output or to the current buffers
protected out ( string $put, boolean $nowrap = false ) : void
$put string
$nowrap boolean
return void
    protected function out($put, $nowrap = false)
    {
        if (empty($put)) {
            return;
        }
        if (!empty($this->buffer)) {
            $this->buffer[count($this->buffer) - 1] .= $put;
        } else {
            if ($this->bodyWidth && !$this->parser->keepWhitespace) {
                // wrap lines
                // get last line
                $pos = strrpos($this->output, "\n");
                if ($pos === false) {
                    $line = $this->output;
                } else {
                    $line = substr($this->output, $pos);
                }
                if ($nowrap) {
                    if ($put[0] != "\n" && $this->strlen($line) + $this->strlen($put) > $this->bodyWidth) {
                        $this->output .= "\n" . $this->indent . $put;
                    } else {
                        $this->output .= $put;
                    }
                    return;
                } else {
                    $put .= "\n";
                    // make sure we get all lines in the while below
                    $lineLen = $this->strlen($line);
                    while ($pos = strpos($put, "\n")) {
                        $putLine = substr($put, 0, $pos + 1);
                        $put = substr($put, $pos + 1);
                        $putLen = $this->strlen($putLine);
                        if ($lineLen + $putLen < $this->bodyWidth) {
                            $this->output .= $putLine;
                            $lineLen = $putLen;
                        } else {
                            $split = preg_split('#^(.{0,' . ($this->bodyWidth - $lineLen) . '})\\b#', $putLine, 2, PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_DELIM_CAPTURE);
                            $this->output .= rtrim($split[1][0]) . "\n" . $this->indent . $this->wordwrap(ltrim($split[2][0]), $this->bodyWidth, "\n" . $this->indent, false);
                        }
                    }
                    $this->output = substr($this->output, 0, -1);
                    return;
                }
            } else {
                $this->output .= $put;
            }
        }
    }