Mar 02, 2015 Tag: Sphinx

PHP Syntax Highlighting in Sphinx

Problem

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.

Solution

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!

Previous topic

TypoScript to Remember

Next topic

Solr for docs.typo3.org

Tags

Archives

Languages

Recent Posts

This Page