Sphinx (documentation tool): setting output tab width

How do you set the tab width in the HTML output of the Sphinx code snippets highlighted by Pygments? By default it is annoying 8, but I want 4. I did not find a word about this setting in Sphinx conf.py.

+6
python python-sphinx
source share
3 answers

You will need to write the Sphinx extension. Add your own Lexer and apply it using VisibleWhitespaceFilter .

0
source share

Add something like this to conf.py:

import re def process_docstring(app, what, name, obj, options, lines): spaces_pat = re.compile(r"( {8})") ll = [] for l in lines: ll.append(spaces_pat.sub(" ",l)) lines[:] = ll def setup(app): app.connect('autodoc-process-docstring', process_docstring) 

See also the Sphinx Docstring preprocessing documentation.

+2
source share

I asked the same question about the sphinx-dev group and found out that this is a problem with Docutils, which is used by Sphinx. Docutils replaces all tabs with 8 spaces and there is currently no way to change this value from Sphinx.

http://groups.google.com/group/sphinx-dev/browse_thread/thread/35b8071ffe9a8feb

The only possible solution seems to be to follow the recommendations of S. Lott and John Powlet in the comments on my question - use spaces instead of tabs.

0
source share

All Articles