Example #1
0
    if ($e = luminous::cacheErrors()) {
        echo '<pre>';
        echo implode("<br/>", $e);
        echo '</pre>';
    }
    echo $t1 - $t . 'seconds <br>';
    echo strlen($_POST['src']) . '<br>';
    echo $out;
}
?>
  <div style='text-align:center'>
    <form method='post' action='interface.php'>
    <select name='lang'>
    <option value='guess'>Guess Language</option>
    <?php 
foreach (luminous::scanners() as $lang => $codes) {
    $def = isset($_POST['lang']) && $_POST['lang'] === $codes[0] ? ' selected' : '';
    echo "<option value='{$codes[0]}'{$def}>{$lang}</option>\n";
}
?>
    <option value='no_such_scanner'>error case</option>
    </select>
    <br/>
    <select name='theme'>
    <?php 
foreach (luminous::themes() as $t) {
    $def = isset($_POST['theme']) && $_POST['theme'] === $t ? ' selected' : '';
    echo sprintf("<option value='%s'%s>%s</option>\n", $t, $def, preg_replace('/\\.css$/i', '', $t));
}
?>
  </select>
Example #2
0
 * That's the test.
 */
$filenames = glob(realpath(__DIR__ . '/../regression') . '/*/*');
sort($filenames);
foreach ($filenames as $filename) {
    if (strpos($filename, '.luminous') !== false) {
        continue;
    }
    if (preg_match('/~$/', $filename)) {
        continue;
    }
    $real_language = basename(dirname($filename));
    $best = array('lang' => '', 'score' => -1, 'codes' => array(null));
    $real = array('lang' => '', 'score' => -1, 'codes' => array(null));
    $text = file_get_contents($filename);
    foreach (luminous::scanners() as $name => $codes) {
        $scanner = $luminous_->scanners->GetScanner($codes[0]);
        $score = $scanner->guess_language($text) . "\n";
        if ($score > $best['score']) {
            $best['score'] = $score;
            $best['lang'] = $name;
            $best['codes'] = $codes;
        }
        if (in_array($real_language, $codes)) {
            $real['score'] = $score;
            $real['lang'] = $name;
            $real['codes'] = $codes;
        }
    }
    if (!in_array($real_language, $best['codes'])) {
        echo 'failed for ' . basename($filename) . "\n";
Example #3
0
 function highlight()
 {
     $this->parse_args();
     // figure out the code
     // error cases are:
     // no input file or source code,
     if ($this->options['code'] === null && $this->options['input-file'] === null) {
         $this->error('No input file or source code specified');
     } elseif ($this->options['code'] !== null && $this->options['input-file'] !== null) {
         $this->error('Input file (-i) and source code specified. You probably ' . 'didn\'t mean this');
     }
     // is there an input file? use that.
     if ($this->options['input-file'] !== null) {
         $c = @file_get_contents($this->options['input-file']);
         if ($c === false) {
             $this->error('Could not read from ' . $this->options['input-file']);
         } else {
             $this->options['code'] = $c;
         }
     } elseif ($this->options['code'] === '-') {
         $code = '';
         while (($line = fgets(STDIN)) !== false) {
             $code .= $line;
         }
         $this->options['code'] = $code;
     }
     // set the formatter
     luminous::set('format', $this->options['format']);
     // lame check that the formatter is okay
     try {
         luminous::formatter();
     } catch (Exception $e) {
         $this->error('Unknown formatter ' . $this->options['format']);
     }
     // set the theme
     $valid_themes = luminous::themes();
     $theme = $this->options['theme'];
     if (!preg_match('/\\.css$/', $theme)) {
         $theme .= '.css';
     }
     if (!luminous::theme_exists($theme)) {
         $this->error('No such theme: ' . $theme);
     } else {
         luminous::set('theme', $theme);
     }
     // set the language
     if ($this->options['lang'] === null) {
         // guessing
         $this->options['lang'] = luminous::guess_language($this->options['code']);
     }
     // user provided language
     $scanners = luminous::scanners();
     $valid_scanner = false;
     foreach ($scanners as $lang => $codes) {
         if (in_array($this->options['lang'], $codes)) {
             $valid_scanner = true;
             break;
         }
     }
     if (!$valid_scanner) {
         $this->error('No such language: ' . $this->options['lang']);
     }
     // other options
     luminous::set('max-height', $this->options['height']);
     luminous::set('line-numbers', $this->options['line-numbers']);
     $h = luminous::highlight($this->options['lang'], $this->options['code']);
     if ($this->options['output-file'] !== null) {
         $r = @file_put_contents($this->options['output-file'], $h, LOCK_EX);
         if ($r === false) {
             $this->error('Could not write to ' . $this->options['output-file']);
         }
     } else {
         echo $h;
     }
     exit(0);
 }