예제 #1
0
 /**
  * Renders a code block
  */
 protected function renderCode($block)
 {
     if (isset($block['language'])) {
         $class = isset($block['language']) ? ' class="language-' . $block['language'] . '"' : '';
         return "<pre><code{$class}>" . $this->highlight(implode("\n", $block['content']) . "\n", $block['language']) . '</code></pre>';
     } else {
         return parent::renderCode($block);
     }
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 protected function renderCode($block)
 {
     if (self::$highlighter === null) {
         self::$highlighter = new Highlighter();
         self::$highlighter->setAutodetectLanguages(['apache', 'nginx', 'bash', 'dockerfile', 'http', 'css', 'less', 'scss', 'javascript', 'json', 'markdown', 'php', 'sql', 'twig', 'xml']);
     }
     try {
         if (isset($block['language'])) {
             $result = self::$highlighter->highlight($block['language'], $block['content'] . "\n");
             return "<pre><code class=\"hljs {$result->language} language-{$block['language']}\">{$result->value}</code></pre>\n";
         } else {
             $result = self::$highlighter->highlightAuto($block['content'] . "\n");
             return "<pre><code class=\"hljs {$result->language}\">{$result->value}</code></pre>\n";
         }
     } catch (DomainException $e) {
         echo $e;
         return parent::renderCode($block);
     }
 }