Fork me on GitHub

Luminous - A PHP Syntax Highlighter

Latest release: 12th January 2013 - v0.7.0

Luminous is a PHP syntax highlighter.

Its main focus is on accuracy and quality of code highlighting, and modern features like CSS colour themes. Luminous is a generic highlighter which can highlight around 30 source code languages, and includes a built-in cache so you don't have to worry about your server load. If you want professional, high quality PHP syntax highlighting for your website or blog, give it a try.

You can try it out here as an online syntax highlighter, and download if it you want to deploy it on your own site.




12th January 2013 - Luminous 0.7.0 release

I finally got around to getting 0.7.0 out.

Highlights (pun):

  • SCSS (nested CSS) scanner
  • CSS and markup cleanup
  • Composer package
  • Licensing change, GPL => LGPL. In my eyes, using Luminous is akin to dynamic linking, and dynamic linking is okay by the GPL. But there is a certain amount of controversy around that. The LGPL is probably more appropriate in definite terms.

Download from the normal place.

Please note: the online demo will still use 0.6.7 for a while as I need to migrate the existing highlights to 0.7 (as the stylesheets are different).[...]

Read more


12th January 2013 - Luminous 0.7.0 release

I finally got around to getting 0.7.0 out.

Highlights (pun):

  • SCSS (nested CSS) scanner
  • CSS and markup cleanup
  • Composer package
  • Licensing change, GPL => LGPL. In my eyes, using Luminous is akin to dynamic linking, and dynamic linking is okay by the GPL. But there is a certain amount of controversy around that. The LGPL is probably more appropriate in definite terms.

Download from the normal place.

Please note: the online demo will still use 0.6.7 for a while as I need to migrate the existing highlights to 0.7 (as the stylesheets are different).[...]

Read more

Luminous 0.7 uses the brilliant (I thought) idea of using CSS counters and ::before pseudo-elements to add line-numbering to HTML output for Luminous, which cleaned and cut back the markup considerably. Unfortunately, as is often the way when you do something clever, there are some unforeseen problems, which are now holding up the process, and a satisfactory solution to all requirements is not obvious.

1) Clean code

Luminous 0.6 uses a table with one row and two cells - line numbers in the left cell, code in the right. HTML fascists (no offence, I'm one too) will scream at the thought of using a table for layout, but simply put, it works, and this is more than can be said for most alternatives. Let's be clear here: tables were used for layout originally because HTML didn't provide good means of doing common things, and we're using tables again because HTML doesn't provide good means of doing less common things. GitHub's brand of Pygments works in the same way, as does BitBuck[...]

Read more

6th September 2012 - More Luminous 0.7 ramblings

As I'm currently killing time from my slightly half-hearted job search while I am learning to drive (which in the UK is a major undertaking), I've been thinking about Luminous 0.7 and what I want it to do.

Firstly, 0.6 was a near-total rewrite about 18 months ago and 0.7 will be nowhere near the same level of change. That's because 0.6.x works pretty well. The core highlighting is awesome, and where it's not awesome, it's because I don't fully understand the language's grammar (see Bash and Ruby, forks/patches are welcome), not because Luminous is inherently crippled. 0.6 moved away from the idea that all languages should be abstracted into one single monolithic lexing algorithm and instead allows lexers to be individually written by hand. It works very well; it doesn't inflate the codebase much and it segregates complexity. It handles those awkward little special cases nicely, on which monolithic highlighters like GeSHi or many of the myriad JavaScript based highlig[...]

Read more

10th June 2012 - Luminous 0.6.7-1 and 0.6.7-2

These are very minor bugfix releases. Hopefully they clear up the strange scrollbar behaviour. These will hopefully be the final releases of the 0.6.x tree.

0.7 should condense a lot of the markup and therefore make problems like this less likely in future. The holy grail for the markup will be to (1) keep explicit line numbering out of the markup and (2) to allow the code-box to be horizontally scrollable without the line numbers disappearing out of the viewport. Both of these I consider important, but the way (1) is currently implemented appears incompatible with any nice solution for (2). Reddit has an interesting solution whereby it injects the entire set of line numbers as a single pseudo-element, (as opposed to each line injecting its own number as a ::before pseudo-element, which is how 0.7 does it now) but this probably isn't appropriate for Luminous because it's (probably) impossible to control the start-number, and it also means having '1 2 .. 999' hard coded in the CSS (which[...]

Read more

24th April 2012 - Luminous 0.6.7 Stable Release

0.6.7 brings a selection of bug fixes to the CSS scanner, a few improvements to JavaDoc style comment detection, and the ability to start line numbering at arbitrary numbers (thanks to Martin Sikora). Unconstrained HTML output's horizontal overflow has also been addressed and should now scroll.


Bug reports to GitHub

This is likely to be the last relase of the 0.6.x tree and further releases will be numbered 0.7.x.

A few of the legacy leftovers will be shaken up, and the markup made a lot cleaner. This blog is currently using an early 0.7 version (see the previous entry to see a code block). If you want to use 0.7 early, feel free to checkout the branch from GitHub but beware instability.

The way I tend to do this is that the master branch should be stable (unit tests passed before committing) and that I make absolutely no guarantees about any other branch. At some point the stable existing 0.7 functionality will be merged back into master, but until then feel free to check it out but bewa[...]

Read more

15th April 2012 - Luminous 0.7 development

Development has started on the 0.7 branch. One of the reasons for advancing the version number is because there are some changes that are going to be backwards incompatible, so this is a heads up.

0.7 will see a radical overhaul of the line numbering system and move it from generating the numbers in PHP to a pure CSS solution. Line numbers have always been a pain; the current solution is to place the numbers and code in two adjacent table cells (I've seen other highlighters do this too) because this solves a number of problems which otherwise occur. This markup is obviously not ideal. Line numbers are more meta or presentational than content and having them in the markup at all seems wrong, and no less so when that markup starts using tables for behaviour and presentation. From a practical point of view, search engines and presumably screen readers and so on have a hard time picking out what's important (the code) from what's not (the numbers), and appearing in Google with a summary consist[...]

Read more

26th February 2012 - 0.6.6 Stable Release

0.6.6 is a relatively minor release that doesn't add any new exciting functionality, but clears up a few things which have been long overdue.

Firstly, Luminous should now work on PHP5.2.0 and above, with the caveat that early versions in the 5.2 tree will generate warnings under strict mode. This does not affect later 5.2 releases. This should be a plus to anyone forced to still support the whole 5.2 tree.

Secondly, the cache has slightly better error logging facilities. By default, Luminous is set to 'verbose' mode and will generate a PHP warning on a fatal cache problem. This is now configurable (via luminous::set('verbose', false). Furthermore, you can now more easily log cache problems for 'private' viewing (i.e. not broadcasting debugging information to your users) with the new luminous::cache_errors() function. See the cache docs for this one.

In the interests of full disclosure, a warning: Since 0.6.5 I've been working full time and have less time to spend o[...]

Read more

25th February 2012 - Luminous and PHP 5.2 compatibility

Some PHP 5.2.0 incompatibilities have recently been squashed and the changes will shortly be making it into a stable release (in the next week or so). For now, you can clone from GitHub, but the changes are so far largely untested.

Luminous should already be compatible with later releases from the PHP 5.2 tree, and you really shouldn't be running such an old PHP version anyway as it is now unsupported, but sometimes you don't have control over your hosting environment.[...]

Read more

The Luminous syntax highlighting plugin for CodeIgniter has been updated. It now uses Luminous 0.6.5 (refer to the 0.6.5 changelog to find out what that means), but more importantly, a small bug that could cause ugly PHP errors has been fixed.

Note that the plugin is not versioned (beyond Git) so the URL and filename are the same.


Download [...]

Read more

15th October 2011 - 0.6.5 Stable Release

0.6.5 adds a number of things. In no particular order, the highlights are:

  • a new theme, Kimono, which is based on the more famous Monokai theme;
  • A version checking script;
  • Some small performance optimisations;
  • A 'plain' diff scanner;
  • And a number of language specific fixes in Django, Ruby, Bash, Perl and PHP.

Overall, the languages fixes in 0.6.5 makes Luminous an even better syntax highlighter than it was before and it is recommended that you upgrade. If you rely on diff highlighting, the diff scanner has been split into two. The previous mode (where embedded code was highlighted too) has been moved into 'diff-pretty'; 'diff' is now simply a plain highlighting mode, but it is less likely to be wrong and it's much faster. If you prefer the old behaviour, use 'diff-pretty'.

Full changelog

Download Luminous[...]

Read more

18th September 2011 - 0.6.4 Stable Release

0.6.4 has been released.

Highlights are:

  • A Django Scanner,
  • a new theme based on GitHub's syntax highlighting,
  • you can now use border-radius on the Luminous div element, and it should look okay,
  • a whole bunch of bug fixes in web language scanners, and some missing keywords added for Python

Everyone should definitely upgrade as the fixed bugs in the web languages were potentially fatal, although I'm not sure they were reachable.

Full changelog:


Read more

28th August 2011 - 0.6.3-1 Stable Release

0.6.3-1 was quietly released a few weeks ago.

To document it: it's a minor release which fixes a single bug in the caching system's timeout. The bug caused cache elements to be removed by default after 9 days of inactivity, rather than the more sensible (and intended) 90.

A cache element's activity is measured by the most recent cache hit for the element.

It is possible to override the timeout by calling

luminous::set('cache-age', $your_new_timeout_in_seconds);

As usual, setting it to -1 or 0 will disable the timeout.[...]

Read more

22nd June 2011 - 0.6.3 Stable Release

Version 0.6.3 of your favourite syntax highlighter is released. Get your copy from the download page.

0.6.3 brings two new features: Highlighting support for Ada code, and the ability to store your highlight cache in a MySQL table. Support for other databases will hopefully come in future. For information on how to do this, check out the cache page of the user documentation.

As well as this, there are a few small general fixes and small fixes for Perl, PHP, Python, and Ruby highlighting.

Full Changelog

As ever, please report problems to the issue tracker on GitHub.

Further, coinciding with this release, the Doxygen API docs are now available online


Read more

15th May 2011 - 0.6.2 Stable Release

0.6.2. is released. Get it from the download site.

0.6.2 sports three exciting new features: a command line interface, a full-page HTML formatter and language guessing. The full page HTML formatter can be accessed by setting the format option to 'html-full'. The language guessing you will find to be either scarily accurate or totally useless depending on what languages you use, but generally, if you're providing full or at least large source snippets of common languages it will be useful.

Be warned that internally the options API has been reworked and it now has some strict validation so you can't set any configuration settings to nonsensical values. If you try to set something nonsensical, it will throw an exception. Obviously, you should be doing a little integration testing before you upgrade any production machines anyway.

There are also a few language fixes for C, Diff, PHP, Ruby and SQL.

Full changelog



PS: the site is slow right now because the host is having YET M[...]

Read more

29th April 2011 - 0.6.1 Stable Release

0.6.1 is released with some major fixes since 0.6.0.

Get it from the usual place (where we now have some actual packages, not just the github generated archives).

The biggest fixes are related to PCRE problems. On the older PHP/PCRE releases, everything is fine, but I upgraded my box to the Kubuntu 11.04 release yesterday (from 10.04 -- fresh install rather than update), and the version of PHP it ships with introduces some huge issues in PCRE (version string: PHP 5.3.5-1ubuntu7 with Suhosin-Patch (cli) built: Apr 17 2011 13:58:11 with PCRE Library Version => 8.12 2011-01-1). The problem is in the backtracking behaviour of PCRE, even straightforward regexes suddenly started hitting the backtracking limit on fairly short strings.

Anyway, despite the apparent unlikeliness of the PHP/PCRE projects pushing an update that breaks *a lot* of my regular expressions, and presumably a lot of other people's as well, I also reproduced this under PHP5.3.5 from Xampp (5.3.1 is fine though), so it looks like thi[...]

Read more

16th April 2011 - 0.6.0 Stable Release

0.6.0 represents an almost total rewrite of Luminous. It's quickly grown from a clean new repository on github with a giant flashing "DON'T USE THIS!" warning, to having now reached the maturity of a stable release. We pretty much threw away all the highlighting related code of 0.5.7 and reimplemented the missing chunks from scratch. The result is that 0.6.0 uses lexical scanners to highlight source code, which is actually a much simpler and more flexible approach than trying to abstract everything into one big generic state machine algorithm.

Download from Github: [zip] [tar.gz]

The change of approach makes Luminous *a lot* more powerful: languages are more complete and the scanners 'understand' source code better and are therefore much more resilient to strange or not-so-strange language constructs. Previously we had situations that were categorised into "we can do that", "we can sort of do that", "we can't do that". We now have a lot more[...]

Read more


<?php require_once('luminous/luminous.php'); ?>
<!DOCTYPE html>
    <?= luminous::head_html(); // outputs stylesheet includes ?>
    <?= luminous::highlight('php', 'echo "hello world";'); ?>