Even with Sphinx 1.2b1 and Pygments 1.6, I needed to call add_lexer to get .. code-block:: json
to do anything. I ended up putting the following code fragment into an extension (docs/_ext/jsonlexer.py
):
def setup(app):
# enable Pygments json lexer
try:
import pygments
if pygments.__version__ >= '1.5':
# use JSON lexer included in recent versions of Pygments
from pygments.lexers import JsonLexer
else:
# use JSON lexer from pygments-json if installed
from pygson.json_lexer import JSONLexer as JsonLexer
except ImportError:
pass # not fatal if we have old (or no) Pygments and no pygments-json
else:
app.add_lexer('json', JsonLexer())
My docs/conf.py
for Sphinx has the following to enable the extension:
import os
import sys
sys.path.insert(0, os.path.abspath('_ext'))
# Add any Sphinx extension module names here, as strings. They can be
# extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['jsonlexer']