/**
  * Accept sections that match the search
  *
  * @return bool Whether the current element of the iterator is acceptable
  *              through this filter
  */
 public function accept()
 {
     $section = $this->current();
     /** @var $section \Icinga\Module\Doc\DocSection */
     $matches = array();
     if (($match = $this->search->search($section->getTitle())) !== null) {
         $matches[] = $match->setMatchType(DocSearchMatch::MATCH_HEADER);
     }
     foreach ($section->getContent() as $lineno => $line) {
         if (($match = $this->search->search($line)) !== null) {
             $matches[] = $match->setMatchType(DocSearchMatch::MATCH_CONTENT)->setLineno($lineno);
         }
     }
     if (!empty($matches)) {
         $this->matches = $matches;
         return $this;
     }
     if ($section->hasChildren()) {
         $this->matches = null;
         return true;
     }
     return false;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $search = null;
     if (($highlightSearch = $this->getHighlightSearch()) !== null) {
         $search = new DocSearch($highlightSearch);
     }
     foreach ($this as $section) {
         $title = $section->getTitle();
         if ($search !== null && ($match = $search->search($title)) !== null) {
             $title = $match->highlight();
         } else {
             $title = $this->getView()->escape($title);
         }
         $number = '';
         for ($i = 0; $i < $this->getDepth() + 1; ++$i) {
             if ($i > 0) {
                 $number .= '.';
             }
             $number .= $this->getSubIterator($i)->key() + 1;
         }
         $this->content[] = sprintf('<a name="%1$s"></a><h%2$d>%3$s. %4$s</h%2$d>', static::encodeAnchor($section->getId()), $section->getLevel(), $number, $title);
         $html = $this->parsedown->text(implode('', $section->getContent()));
         if (empty($html)) {
             continue;
         }
         $html = preg_replace_callback('#<pre><code class="language-php">(.*?)</code></pre>#s', array($this, 'highlightPhp'), $html);
         $html = preg_replace_callback('/<img[^>]+>/', array($this, 'replaceImg'), $html);
         $html = preg_replace_callback('#<blockquote>.+</blockquote>#ms', array($this, 'markupNotes'), $html);
         $html = preg_replace_callback('/<a\\s+(?P<attribs>[^>]*?\\s+)?href="(?:(?!http:\\/\\/)[^"#]*)#(?P<fragment>[^"]+)"/', array($this, 'replaceLink'), $html);
         if ($search !== null) {
             $html = $this->highlightSearch($html, $search);
         }
         $this->content[] = $html;
     }
     return implode("\n", $this->content);
 }