Mar 02, 2015 Tag: Sphinx

PHP Syntax Highlighting in Sphinx


Sphinx uses ‘Pygments’ for syntax highlighting. And Pygments does a syntax check first. For PHP this check only succeeds for code starting with <?php unless you call Pygments with the parameter startinline=True. Problem: Sphinx will not let you specify that parameter. Solution: Add some lines to to change the default behavior of the PHPLexer in Pygments.


Fabien Potencier is presenting a solution to enable highlighting for PHP code not between <?php ... ?> by default. Add these lines to the file of your Sphinx documentation project:

# load PhpLexer
from sphinx.highlighting import lexers
from pygments.lexers.web import PhpLexer

# enable highlighting for PHP code not between <?php ... ?> by default
lexers['php'] = PhpLexer(startinline=True)
lexers['php-annotations'] = PhpLexer(startinline=True)



comments powered by Disqus

Previous topic

TypoScript to Remember

Next topic

TYPO3 Extbase Query Methods




Recent Posts

This Page