예제 #1
0
 /**
  * @see	\wcf\system\bbcode\highlighter\Highlighter::highlight()
  */
 public function highlight($string)
 {
     $string = str_replace('span', '053a0024219422ca9215c0a3ed0578ee76cff477', $string);
     // fix to not highlight the spans of the highlighter
     $string = str_replace(':link', ':li@@nk', $string);
     // fix to highlight pseudo-class different than tag
     $string = str_replace(array('right:', 'left:'), array('r@@ight:', 'l@@eft:'), $string);
     // fix to highlight properties different than values
     $string = strtr($string, self::$duplicates);
     // fix to highlight properties different than tags
     $string = parent::highlight($string);
     $string = strtr($string, array_flip(self::$duplicates));
     // fix to highlight properties different than tags
     $string = str_replace(array('r@@ight', 'l@@eft'), array('right', 'left'), $string);
     // fix to highlight properties different than values
     $string = str_replace('li@@nk', 'link', $string);
     // fix to highlight pseudo-class different than tag
     return str_replace('053a0024219422ca9215c0a3ed0578ee76cff477', 'span', $string);
     // fix to not highlight the spans of the highlighter
 }
예제 #2
0
파일: GeSHi11x.php 프로젝트: philip/phd
 /**
  * Highlight a given piece of source code.
  *
  * @param string $text   Text to highlight
  * @param string $role   Source code role to use (php, xml, html, ...)
  * @param string $format Output format (pdf, xhtml, troff, ...)
  *
  * @return string Highlighted code
  */
 public function highlight($text, $role, $format)
 {
     $this->geshi->setSource($text);
     $lang = $this->getGeSHiLanguage($role);
     if ($lang === null) {
         //GeSHi does not support this language.
         // fall back to the default highlighter
         return parent::highlight($text, $role, $format);
     }
     //FIXME: perhaps it is more efficient to
     // keep a geshi instance for each single programming language.
     $this->geshi->setLanguage($lang);
     return $this->geshi->parseCode();
 }
 private function processSubLanguage()
 {
     try {
         $hl = new Highlighter();
         $hl->autodetectSet = $this->autodetectSet;
         $explicit = is_string($this->top->subLanguage);
         if ($explicit && !isset(array_flip(self::$languages)[$this->top->subLanguage])) {
             return $this->escape($this->modeBuffer);
         }
         if ($explicit) {
             $res = $hl->highlight($this->top->subLanguage, $this->modeBuffer, true, isset($this->continuations[$this->top->subLanguage]) ? $this->continuations[$this->top->subLanguage] : null);
         } else {
             $res = $hl->highlightAuto($this->modeBuffer, count($this->top->subLanguage) ? $this->top->subLanguage : null);
         }
         // Counting embedded language score towards the host language may
         // be disabled with zeroing the containing mode relevance. Usecase
         // in point is Markdown that allows XML everywhere and makes every
         // XML snippet to have a much larger Markdown score.
         if ($this->top->relevance > 0) {
             $this->relevance += $res->relevance;
         }
         if ($explicit) {
             $this->continuations[$this->top->subLanguage] = $res->top;
         }
         return $this->buildSpan($res->language, $res->value, false, true);
     } catch (\Exception $e) {
         error_log("TODO, is this a relevant catch?");
         error_log($e);
         return $this->escape($this->modeBuffer);
     }
 }