function highlight_luminous($path) { $lang = trim(substr(ext($path), 1)); if ($lang === '') { return; } $src = file_get_contents($path); return Luminous::highlight($lang, $src, false); }
function doAjax() { global $useCache; $language = $_POST['language']; $code = $_POST['code']; // Arbitrarily sized security check if (strlen($code) < 500) { echo Luminous::highlight($language, $code, $useCache); } die(0); // we're done now. }
<title>Setting options</title> <?php echo Luminous::headHtml(); ?> </head> <body> <p> There are two ways you can set options: globally via the set() method, and per-call in the highlight() method. Let's disable auto-linking and make all highlights begin at line 17 via the global call. <?php // NOTE: this is equivalent to calling luminous::set(array('auto-link' => false, 'start-line' => 17)); Luminous::set('autoLink', false); Luminous::set('startLine', 17); echo Luminous::highlight($language, $code); ?> <p> Now let's override both of those for the duration of the next call <?php echo Luminous::highlight($language, $code, array('autoLink' => true, 'startLine' => 1)); ?> <p> When we next call highlight(), the options will be back to their global states: <?php echo Luminous::highlight($language, $code); ?> <p> We can get the current value for an option by calling setting(): auto-link is: <?php echo var_dump(Luminous::setting('autoLink')); ?> . </body> </html>
<!DOCTYPE html> <html> <head> <title>Inline code highlighting with AJAX example</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <?php echo Luminous::headHtml(); ?> </head> <body> Lorem ipsum dolor sit amet, <?php echo Luminous::highlight('c', '#include <stdio.h>'); ?> consectetur adipiscing elit. Pellentesque <?php echo Luminous::highlight('c', 'int main()'); ?> orci eros, pellentesque sed elementum eu, mattis nec neque. Vestibulum hendrerit leo vel mi tristique mollis. Mauris magna odio, porta ut fringilla iaculis, <?php echo Luminous::highlight('c', 'printf("hello, world!\\n");'); ?> placerat eu urna. Vivamus non nisi nec <?php echo Luminous::highlight('c', 'return 0;'); ?> ante euismod vehicula. Curabitur nec enim tortor. Proin viverra ligula nec quam pulvinar vehicula. Vivamus turpis diam </body> </html>
<?php require __DIR__ . '/helper.php'; $files = array('Standard example' => 'example.php', 'AJAX interface' => 'ajax.php', 'Full page output' => 'fullpage.php', 'Inline code' => 'inline.php', 'Theme switcher' => 'themeswitcher.php', 'Setting options' => 'options.php'); if (isset($_GET['file']) && in_array($_GET['file'], $files)) { Luminous::set('includeJquery', true); $source = Luminous::highlight('php', file_get_contents(__DIR__ . '/' . $_GET['file'])); Luminous::set('theme', 'github'); $head = Luminous::headHtml(); echo <<<EOF <!DOCTYPE html> <html> <head> <title></title> <style> body { font-size: smaller; margin: 0;} </style> {$head} </head> <body> {$source} </body> </html> EOF; exit(0); } ?> <!DOCTYPE html> <html> <head> <title>Luminous examples</title> <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<?php if (php_sapi_name() !== 'cli') { die('This must be run from the command line'); } /* * Very simple check to ensure that each scanner is okay, and does not * contain any syntax errors which prevent PHP compilation, or any errors * which are trivially possible to reproduce. * * Scanners are included lazily, so it's possible that a syntax error could * go undetected for some time */ require 'helper.inc'; error_reporting(E_ALL | E_STRICT); foreach (Luminous::scanners() as $codes) { Luminous::highlight($codes[0], ' '); }
echo Luminous::highlight('php', <<<EOF <?php /** * @ingroup LuminousUtils * @internal * @brief Decodes a PCRE error code into a string * @param errcode The error code to decode (integer) * @return A string which is simply the name of the constant which matches the * error code (e.g. 'PREG_BACKTRACK_LIMIT_ERROR') * * @todo this should all be namespaced */ function pcre_error_decode(\$errcode) { switch (\$errcode) { case PREG_NO_ERROR: return 'PREG_NO_ERROR'; case PREG_INTERNAL_ERROR: return 'PREG_INTERNAL_ERROR'; case PREG_BACKTRACK_LIMIT_ERROR: return 'PREG_BACKTRACK_LIMIT_ERROR'; case PREG_RECURSION_LIMIT_ERROR: return 'PREG_RECURSION_LIMIT_ERROR'; case PREG_BAD_UTF8_ERROR: return 'PREG_BAD_UTF8_ERROR'; case PREG_BAD_UTF8_OFFSET_ERROR: return 'PREG_BAD_UTF8_OFFSET_ERROR'; default: return 'Unknown error code'; } } EOF , $useCache);
function testCache() { global $sqlExecuted; $sqlExecuted = false; Luminous::set('sql_function', 'sql'); // this will throw a cache not creatable warning which we don't really care // about @Luminous::highlight('plain', '123', true); assert($sqlExecuted); }