public function convert()
{
if (!empty($this->text)) {
return $this->text;
}
$html = $this->preprocess($this->html);
$this->document = new DOMDocument();
set_error_handler(array(__CLASS__, 'silence_errors'));
$this->document->loadHTML($html);
restore_error_handler();
// Remove the DOCTYPE
// Seems to cause segfaulting if we don't do this
if ($this->document->firstChild instanceof DOMDocumentType) {
$this->document->removeChild($this->document->firstChild);
}
$this->text = $this->parse_children($this->document->getElementsByTagName('body')->item(0));
$this->text = preg_replace("#\n{3,}#", "\n\n", $this->text);
$this->text = $this->wrap($this->text, 80);
$this->text .= $this->generate_links();
return $this->text;
}