In the lastest trunk revision of Sphinx, when section numbers are turned on via:
.. toctree::
:numbered:
They look like
1. Section
1.1. Subsection
In my opinion this looks ugly. I'd rather have:
1 Section
1.1 Subsection
Here's some changes that allow you to specify a custom section number
suffix just by adding the following line to the conf.py file:
secnumber_suffix = u'\u00a0\u00a0' #\u00a0 is non-break space
In sphinx/config.py add the following line somewhere inside the
config_values = dict() initialization:
secnumber_suffix = ('. ', 'html'), #By default, use original suffix.
In sphinx/writers/html.py, make the following changes to class
HTMLTranslator(BaseTranslator):
def __init__(self, builder, *args, **kwds):
...
self.secnumber_suffix = builder.config.secnumber_suffix
def visit_reference(self, node):
...
if node.hasattr('secnumber'):
self.body.append(('%s' + self.secnumber_suffix) %
'.'.join(map(str, node['secnumber'])))
def add_secnumber(self, node):
if node.hasattr('secnumber'):
self.body.append('.'.join(map(str, node['secnumber'])) +
self.secnumber_suffix)
elif isinstance(node.parent, nodes.section):
anchorname = '#' + node.parent['ids'][0]
if anchorname not in self.builder.secnumbers:
anchorname = '' # try first heading which has no anchor
if anchorname in self.builder.secnumbers:
numbers = self.builder.secnumbers[anchorname]
self.body.append('.'.join(map(str, numbers)) +
self.secnumber_suffix)
In order to make the resulting HTML look better I found the following
CSS changes also helpful (assuming the "default" theme and
globaltoc.html in the sidebar):
@import url("default.css");
div.sphinxsidebar ul,
div.sphinxsidebar ul.want-points {
list-style: none;
padding-left: 1.5em;
}
div.sphinxsidebar ul ul,
div.sphinxsidebar ul.want-points {
list-style: none;
padding-left: 0;
}
div.sphinxsidebarwrapper li {
text-indent: -2em;
}
div.sphinxsidebar a.current {
color: yellow;
}
With section numbering turned on, you really don't need bullets.
Unless you mess with the text-indent and padding-left, long section
titles wrap underneath the section numbers. The above CSS therefore
tries to simulate "hanging-indents".
Caveat: I've only tested on a few cases, and I'm not very familiar
with sphinx... but the changes work for me.
--
You received this message because you are subscribed to the Google Groups
"sphinx-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sphinx-dev?hl=en.