Mar 02, 2015 Tag: Sphinx
See also: About 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 conf.py
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 conf.py
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)
Enjoy!