protected function format($str, $indent = true)
    {
        $spaces = str_repeat(' ', ((int)$indent) * $this->indent);

        return $spaces . trim(
            str_replace(
                "\n",
                "\n" . $spaces,
                (php_sapi_name() != 'cli' ? htmlspecialchars($str) : $str)
            )
        ) . "\n";
    }