コード例 #1
0
 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);
     }
 }