} if (isset($_POST['format'])) { Luminous::set('format', $_POST['format']); } $line_numbers = true; if (!empty($_POST) && !isset($_POST['line-numbers'])) { $line_numbers = false; } $line_numbers_start = false; if (!empty($_POST) && isset($_POST['line-numbers-start'])) { $line_numbers_start = (int) $_POST['line-numbers-start']; if ($line_numbers_start > 0) { Luminous::set('start-line', $line_numbers_start); } } Luminous::set('line-numbers', $line_numbers); ?> <!DOCTYPE html> <html> <head> <?php echo Luminous::headHtml(); ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <?php if (count($_POST)) { $lang = $_POST['lang']; if ($lang === 'guess') {
<?php include 'helper.php'; Luminous::set('format', 'html-inline'); Luminous::set('includeJavascript', false); ?> <!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;');
<!DOCTYPE html> <html> <head> <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')); ?> .
<?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 /* Example using AJAX to prettify inline code */ require_once 'helper.php'; Luminous::set('lineNumbers', false); Luminous::set('includeJavascript', true); Luminous::set('format', 'html-inline'); // define a quick and dirty AJAX interface 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. } if (!empty($_POST)) { // php is stupid. if (get_magic_quotes_gpc()) { foreach ($_POST as &$p) { $p = stripslashes($p); } } doAjax(); } ?> <!DOCTYPE html>
<?php // Theme switcher example require_once 'helper.php'; Luminous::set('includeJavascript', true); // This isn't an injection or XSS vulnerability. You don't have to worry // about sanitising this, Luminous won't use it if it's not a valid theme file. if (!empty($_GET)) { Luminous::set('theme', $_GET['theme_switcher']); } ?> <!DOCTYPE HTML> <html> <head> <title>Theme Switcher Example</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <?php echo Luminous::headHtml(); ?> <script type='text/javascript'> $(document).ready(function() { // theme switcher change handler $('#theme_switcher').change(function(){ // get the /path/to/style/ via the current theme's href attribute var current_url = $('#luminous-theme').attr('href'); var base_url = current_url.replace(/[^/]*$/, ''); // now replace the href with the new theme's path $('#luminous-theme').attr('href', base_url + $(this).val() );
<?php // very easy, set the format to html-full require_once 'helper.php'; Luminous::set('format', 'html-full'); echo luminous::highlightFile('php', 'themeswitcher.php', $useCache);
<?php $luminousRoot = dirname(__DIR__); if (file_exists($luminousRoot . '/vendor/autoload.php')) { // standalone install require_once $luminousRoot . '/vendor/autoload.php'; } elseif (file_exists($luminousRoot . '/../../autoload.php')) { // dep install require_once $luminousRoot . '/../../autoload.php'; } else { die('Please install the Composer autoloader by running `composer install` from within ' . $luminousRoot . PHP_EOL); } set_time_limit(2); // This var is because on my dev machine I symlink some directories and // from that, PHP/Luminous cannot figure out where it is relative to the // document root. $httpPath = '../'; $useCache = false; Luminous::set('relative-root', $httpPath); Luminous::set('include-jquery', true);
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); }
if (php_sapi_name() !== 'cli') { die('This must be run from the command line'); } $luminousRoot = dirname(dirname(__DIR__)); if (file_exists($luminousRoot . '/vendor/autoload.php')) { // standalone install require_once $luminousRoot . '/vendor/autoload.php'; } elseif (file_exists($luminousRoot . '/../../autoload.php')) { // dep install require_once $luminousRoot . '/../../autoload.php'; } else { die('Please install the Composer autoloader by running `composer install` from within ' . $luminousRoot . PHP_EOL); } $path = __DIR__; Luminous::set('format', null); $output_ext = '.luminous'; $missing_output = array(); $diff_output = array(); $default_target = scandir($path); foreach ($default_target as $k => $v) { if (!is_dir($v) || $v[0] == '.') { unset($default_target[$k]); } } function ext($path) { return preg_replace('/.*(?=\\.)/', '', $path); } function highlight_luminous($path) {