Fork me on GitHub

What makes Luminous a great PHP syntax highlighter?

High Quality PHP Syntax Highlighting

  • Easy to use - Highlighting requires only one line of code.
  • CSS themes - There are several light and dark themes included and you can easily create more.
  • Includes transparent caching so your site should stay fast
  • Powerful: It uses lexical scanners to highlight your source code, which means syntax highlighting is high quality and accurate. It's powerful enough to do clever things like:
    1. Handle mixed PHP/HTML/CSS/JavaScript and Ruby on Rails-like language nesting,
    2. highlight source code inside diff/patch files,
    3. highlight Ruby's string interpolation and balanced delimiters.
  • Well documented and open source - Stuck, or want to extend Luminous? Check out the documentation section.
  • Safe - Luminous has a large test database and is frequently tested against random input, so you know it'll handle your code gracefully.

Luminous as a GeSHi alternative: Why not just use GeSHi?

GeSHi is another PHP syntax highlighter and has existed for much longer. Unfortunately GeSHi has a number of obvious and not so obvious problems []. GeSHi uses a one-size-fits-all approach to languages, and as a result, can struggle on complex languages. Luminous employs a totally different approach by implementing individually written lexers for each language, and as a result, the highlighting is better. It also means that Luminous's internals tend to be more transparent (although more work may be involved in writing such a lexer), therefore Luminous is fairly easy to extend and customise under the hood (if you so desire).

Furthermore, GeSHi makes things like CSS styles difficult (it defines colours inside the language files), and it makes no real effort to work around PCRE (Perl compatible regular expressions - PHP's regular expression library) limitations; GeSHi's infrastructure is sufficiently lacking that it has to rely on complex regular expressions which can easily crash PCRE, whereas Luminous is explicitly tested against nonsense code to check that it works correctly.

GeSHi is generally a bit faster than Luminous in terms of raw throughput. However, Luminous includes a caching system which means in reality, Luminous will be much faster on average.