Sunday, August 19, 2012

Sphinx Doc, JSON highlight and Sphinx extensions: kung-fu

At the moment Pygments which used by Sphinx Doc haven't support for JSON code highlight which is really sad.

I've not found any useful information how to do it quickly. So here is my way:
  1. I've found custom pygments lexer which support JSON: pygments-json . I will be part of pygments soon
  2. It wasn't clear to me how to add custom pygments lexer to sphinx, my google-fu isn't good today
  3. A bit more googling gave me Sphinx Extensions API , especially add_lexer method of Sphinx instance
Ok, now it's clear to me how to add new lexer. I've created ext/hijson folder within source, to __init__.py I've added setup function:

Also here is how to add support of ext folder as folder with custom extensions So, pip install pygments-json and use

.. code-block:: json

Nice and smooth:

No comments:

Post a Comment