$inline = true; } elseif ($a == '-v') { $verbose = true; } elseif ($a == '--help' || !array_key_exists($a, $doctypes)) { print_help(); } else { $doctypes_[] = $argv[$i]; } } // set_error_handler('err_handler'); $out = array(); $num_requests = count($samples) * count($doctypes_); $req = 0; luminous::set('format', $inline ? 'html_inline' : 'html'); foreach ($samples as $s) { $formatter = luminous::formatter(); $formatter->line_numbers = true; $formatter->link = true; // At the moment, this just stops TARGET attributes on links, which happen // to be highly convenient but the w3c in their infinite wisdom decided // were invalid in HTML4 strict. $formatter->strict_standards = true; $src = file_get_contents($s); $output = $formatter->format($src); $out[$s] = array(); foreach ($doctypes_ as $spec) { $doctype = $doctypes[$spec]; $html = @htmlify($output, $doctype); try { $return = validate($html); } catch (Exception $e) {
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); }