getIterator(), $chapter); if ($filter->isEmpty()) { throw new ChapterNotFoundException( mt('doc', 'Chapter %s not found'), $chapter ); } parent::__construct( $filter, RecursiveIteratorIterator::SELF_FIRST ); } else { parent::__construct($tree->getIterator(), RecursiveIteratorIterator::SELF_FIRST); } $this->tree = $tree; $this->parsedown = Parsedown::instance(); } /** * Syntax highlighting for PHP code * * @param array $match * * @return string */ protected function highlightPhp($match) { return '
' . highlight_string(htmlspecialchars_decode($match[1]), true) . ''; } /** * Markup notes * * @param array $match * * @return string */ protected function markupNotes($match) { $doc = new DOMDocument(); $doc->loadHTML($match[0]); $xpath = new DOMXPath($doc); $blockquote = $xpath->query('//blockquote[1]')->item(0); /* @var $blockquote \DOMElement */ if (strtolower(substr(trim($blockquote->nodeValue), 0, 5)) === 'note:') { $blockquote->setAttribute('class', 'note'); } return $doc->saveXML($blockquote); } /** * Replace img src tags * * @param $match * * @return string */ protected function replaceImg($match) { $doc = new DOMDocument(); $doc->loadHTML($match[0]); $xpath = new DOMXPath($doc); $img = $xpath->query('//img[1]')->item(0); /* @var $img \DOMElement */ $img->setAttribute('src', Url::fromPath($img->getAttribute('src'))->getAbsoluteUrl()); return substr_replace($doc->saveXML($img), '', -2, 1); // Replace '/>' with '>' } /** * Replace link * * @param array $match * * @return string */ protected function replaceLink($match) { if (($section = $this->tree->getNode($this->decodeAnchor($match['fragment']))) === null) { return $match[0]; } /** @type $section \Icinga\Module\Doc\DocSection */ $path = $this->getView()->getHelper('Url')->url( array_merge( $this->urlParams, array( 'chapter' => $this->encodeUrlParam($section->getChapter()->getId()) ) ), $this->url, false, false ); $url = $this->getView()->url($path); /** @type \Icinga\Web\Url $url */ $url->setAnchor($this->encodeAnchor($section->getId())); return sprintf( 'getNoFollow() ? 'rel="nofollow" ' : '', $url->getAbsoluteUrl() ); } /** * {@inheritdoc} */ public function render() { foreach ($this as $section) { $this->content[] = sprintf( '
(.*?)
#s',
array($this, 'highlightPhp'),
$this->parsedown->text(implode('', $section->getContent()))
);
$html = preg_replace_callback(
'/.+#ms', array($this, 'markupNotes'), $html ); $this->content[] = preg_replace_callback( '/[^>]*?\s+)?href="(?:(?!http:\/\/)[^#]*)#(?P