Esempio n. 1
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);
     }
 }
 * POSSIBILITY OF SUCH DAMAGE.
 */
set_time_limit(60);
$start = microtime(true);
require_once "../Highlight/Autoloader.php";
spl_autoload_register("Highlight\\Autoloader::load");
$styles = array();
$d = dir(".." . DIRECTORY_SEPARATOR . "styles");
while (false !== ($e = $d->read())) {
    if ($e[0] !== "." && $e !== "default.css" && strpos($e, ".css") !== false) {
        $styles[] = $e;
    }
}
sort($styles);
use Highlight\Highlighter;
$hl = new Highlighter();
$hl->setAutodetectLanguages($hl->listLanguages());
$tableRows = "";
$failed = array();
foreach ($hl->listLanguages() as $name) {
    $sn = $name;
    $snippet = file_get_contents("../test/detect/{$sn}/default.txt");
    $r = $hl->highlightAuto($snippet);
    $passed = $r->language === $name;
    $res = "<div class=\"test\"><var class=\"" . ($passed ? "passed" : "failed") . "\">{$r->language}</var>" . " ({$r->relevance})<br>";
    if (isset($r->secondBest)) {
        $res .= "{$r->secondBest->language}" . " ({$r->secondBest->relevance})";
    }
    $tableRows .= "<tr><th>{$name}{$res}</th><td class=\"{$name}\">\n        <pre><code class=\"hljs {$name}\">{$r->value}</code></pre></td></th>";
    if (!$passed) {
        $failed[] = $name;