protected function convertHtmlToText(\DOMNodeList $nodes)
    {
        $text = "";

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            $lineBreaksBefore = 0;
            $lineBreaksAfter = 0;
            $lineCharBefore = "";
            $lineCharAfter = "";
            $prefix = "";
            $suffix = "";

            if (in_array($node->nodeName, ["h1", "h2", "h3", "h4", "h5", "h6", "h"])) {
                $lineCharAfter = "=";
                $lineBreaksAfter = 2;
            } elseif (in_array($node->nodeName, ["p", "td"])) {
                $lineBreaksAfter = 2;
            } elseif (in_array($node->nodeName, ["div"])) {
                $lineBreaksAfter = 1;
            }

            if ($node->nodeName === "h1") {
                $lineCharBefore = "*";
                $lineCharAfter = "*";
            } elseif ($node->nodeName === "h2") {
                $lineCharBefore = "=";
            }

            if ($node->nodeName === '#text') {
                $textContent = html_entity_decode($node->textContent, ENT_COMPAT | ENT_HTML401, $this->getCharset());

                // Replace tabs (used to mark links below) and other control characters
                $textContent = preg_replace("/[\r\n\f\v\t]+/", "", $textContent);

                if ($textContent !== "") {
                    $text .= $textContent;
                }
            } elseif ($node->nodeName === 'a') {
                $href = "";
                if ($node->attributes !== null) {
                    $hrefAttribute = $node->attributes->getNamedItem("href");
                    if ($hrefAttribute !== null) {
                        $href = (string)$hrefAttribute->nodeValue;
                    }
                }
                if ($href !== "") {
                    $suffix = " (\t" . $href . "\t)";
                }
            } elseif ($node->nodeName === 'b' || $node->nodeName === 'strong') {
                $prefix = "*";
                $suffix = "*";
            } elseif ($node->nodeName === 'hr') {
                $text .= str_repeat('-', 75) . "\n\n";
            }

            if ($node->hasChildNodes()) {
                $text .= str_repeat("\n", $lineBreaksBefore);

                $addText = $this->convertHtmlToText($node->childNodes);

                $text .= $prefix;

                $text .= $lineCharBefore ? str_repeat($lineCharBefore, 75) . "\n" : "";
                $text .= $addText;
                $text .= $lineCharAfter ? "\n" . str_repeat($lineCharAfter, 75) . "\n" : "";

                $text .= $suffix;

                $text .= str_repeat("\n", $lineBreaksAfter);
            }
        }

        // Remove unnecessary white spaces at he beginning/end of lines
        $text = preg_replace("/(?:^[ \t\f]+([^ \t\f])|([^ \t\f])[ \t\f]+$)/m", "\\1\\2", $text);

        // Replace multiple line-breaks
        $text = preg_replace("/[\r\n]{2,}/", "\n\n", $text);

        return $text;
    }