mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fixed docstring dedenting and made the html writer more configurable in the sense that it doesn't change behavior based on the builder name any longer.
This commit is contained in:
parent
4fb3723102
commit
a3db873c47
4
CHANGES
4
CHANGES
@ -15,6 +15,10 @@ New features added
|
||||
* The `automodule` directive now supports the ``synopsis``,
|
||||
``deprecated`` and ``platform`` options.
|
||||
|
||||
* The HTML builders have two additional attributes now that can be used
|
||||
to disable the anchor-link creation after headlines and definition
|
||||
links. EXPERIMENTAL
|
||||
|
||||
|
||||
Release 0.4.1 (Jul 5, 2008)
|
||||
===========================
|
||||
|
@ -301,6 +301,8 @@ class StandaloneHTMLBuilder(Builder):
|
||||
supported_image_types = ['image/svg+xml', 'image/png', 'image/gif',
|
||||
'image/jpeg']
|
||||
searchindex_filename = 'searchindex.json'
|
||||
add_header_links = True
|
||||
add_definition_links = True
|
||||
|
||||
def init(self):
|
||||
"""Load templates."""
|
||||
@ -810,6 +812,10 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
||||
copysource = False
|
||||
supported_image_types = ['image/png', 'image/gif', 'image/jpeg']
|
||||
|
||||
# don't add links
|
||||
add_header_links = False
|
||||
add_definition_links = False
|
||||
|
||||
def init(self):
|
||||
StandaloneHTMLBuilder.init(self)
|
||||
# the output files for HTML help must be .html only
|
||||
|
@ -12,6 +12,7 @@
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import types
|
||||
import inspect
|
||||
import textwrap
|
||||
@ -158,17 +159,25 @@ def prepare_docstring(s):
|
||||
of nested_parse().) An empty line is added to act as a separator between
|
||||
this docstring and following content.
|
||||
"""
|
||||
if not s or s.isspace():
|
||||
return ['']
|
||||
s = s.expandtabs()
|
||||
nl = s.rstrip().find('\n')
|
||||
if nl == -1:
|
||||
# Only one line...
|
||||
return [s.strip(), '']
|
||||
# The first line may be indented differently...
|
||||
firstline = s[:nl].strip()
|
||||
otherlines = textwrap.dedent(s[nl+1:])
|
||||
return [firstline] + otherlines.splitlines() + ['']
|
||||
lines = s.expandtabs().splitlines()
|
||||
# Find minimum indentation of any non-blank lines after first line.
|
||||
margin = sys.maxint
|
||||
for line in lines[1:]:
|
||||
content = len(line.lstrip())
|
||||
if content:
|
||||
indent = len(line) - content
|
||||
margin = min(margin, indent)
|
||||
# Remove indentation.
|
||||
if lines:
|
||||
lines[0] = lines[0].lstrip()
|
||||
if margin < sys.maxint:
|
||||
for i in range(1, len(lines)): lines[i] = lines[i][margin:]
|
||||
# Remove any trailing or leading blank lines.
|
||||
while lines and not lines[-1]:
|
||||
lines.pop()
|
||||
while lines and not lines[0]:
|
||||
lines.pop(0)
|
||||
return lines
|
||||
|
||||
|
||||
def get_module_charset(module):
|
||||
@ -441,8 +450,8 @@ def generate_rst(what, name, members, options, add_content, document, lineno,
|
||||
# unqualified :members: given
|
||||
if what == 'module':
|
||||
# for implicit module members, check __module__ to avoid documenting
|
||||
# imported objects
|
||||
members_check_module = True
|
||||
# imported objects if __all__ is not defined
|
||||
members_check_module = not hasattr(todoc, '__all__')
|
||||
all_members = inspect.getmembers(todoc)
|
||||
else:
|
||||
if options.inherited_members:
|
||||
|
@ -71,7 +71,7 @@ class HTMLTranslator(BaseTranslator):
|
||||
if node.parent['desctype'] in ('class', 'exception'):
|
||||
self.body.append('%s ' % node.parent['desctype'])
|
||||
def depart_desc_signature(self, node):
|
||||
if node['ids'] and self.builder.name != 'htmlhelp':
|
||||
if node['ids'] and self.builder.add_definition_links:
|
||||
self.body.append(u'<a class="headerlink" href="#%s" ' % node['ids'][0] +
|
||||
u'title="Permalink to this definition">\u00B6</a>')
|
||||
self.body.append('</dt>\n')
|
||||
@ -342,7 +342,7 @@ class HTMLTranslator(BaseTranslator):
|
||||
|
||||
def depart_title(self, node):
|
||||
close_tag = self.context[-1]
|
||||
if self.builder.name != 'htmlhelp' and \
|
||||
if self.builder.add_header_links and \
|
||||
(close_tag.startswith('</h') or
|
||||
close_tag.startswith('</a></h')) and \
|
||||
node.parent.hasattr('ids') and node.parent['ids']:
|
||||
|
Loading…
Reference in New Issue
Block a user