public function render($text)
    {
        $text = $this->config->onStart($text);

        $linesIterator = new \ArrayIterator(preg_split("/\015\012|\015|\012/", $text)); // we split the text at all line feeds
        $this->documentGenerator->clear();
        $this->errors = array();

        while ($linesIterator->valid()) {
            $line = $linesIterator->current();
            if ($line != '') {
                $blockGen = $this->parseBlock($linesIterator, $line, null);
                if (is_object($blockGen)) {
                    $this->documentGenerator->addBlock($blockGen);
                    continue;
                }
            }
            // no block found, we use a default block
            if (trim($line) == '') {
                $blockGenerator = new Generator\SingleLineBlock($this->documentGenerator->getConfig());
            } else {
                $inline = $this->inlineParser->parse($line);
                $blockGenerator = $this->documentGenerator->getDefaultBlock($inline);
                if (!$blockGenerator) {
                    $blockGenerator = new Generator\SingleLineBlock($this->documentGenerator->getConfig());
                    $blockGenerator->setLineAsString($inline);
                }
            }
            $this->documentGenerator->addBlock($blockGenerator);
            $this->nextLine($linesIterator);
        }

        $result = $this->documentGenerator->generate();

        if ($this->documentGenerator->getConfig()->generateHeaderFooter) {
            $result = $this->documentGenerator->generateHeader()
                     .$result
                     .$this->documentGenerator->generateFooter();
        }

        return $this->config->onParse($result);
    }