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:
4
CHANGES
4
CHANGES
@@ -15,6 +15,10 @@ New features added
|
|||||||
* The `automodule` directive now supports the ``synopsis``,
|
* The `automodule` directive now supports the ``synopsis``,
|
||||||
``deprecated`` and ``platform`` options.
|
``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)
|
Release 0.4.1 (Jul 5, 2008)
|
||||||
===========================
|
===========================
|
||||||
|
|||||||
@@ -301,6 +301,8 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
supported_image_types = ['image/svg+xml', 'image/png', 'image/gif',
|
supported_image_types = ['image/svg+xml', 'image/png', 'image/gif',
|
||||||
'image/jpeg']
|
'image/jpeg']
|
||||||
searchindex_filename = 'searchindex.json'
|
searchindex_filename = 'searchindex.json'
|
||||||
|
add_header_links = True
|
||||||
|
add_definition_links = True
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""Load templates."""
|
"""Load templates."""
|
||||||
@@ -810,6 +812,10 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
copysource = False
|
copysource = False
|
||||||
supported_image_types = ['image/png', 'image/gif', 'image/jpeg']
|
supported_image_types = ['image/png', 'image/gif', 'image/jpeg']
|
||||||
|
|
||||||
|
# don't add links
|
||||||
|
add_header_links = False
|
||||||
|
add_definition_links = False
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
StandaloneHTMLBuilder.init(self)
|
StandaloneHTMLBuilder.init(self)
|
||||||
# the output files for HTML help must be .html only
|
# the output files for HTML help must be .html only
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import types
|
import types
|
||||||
import inspect
|
import inspect
|
||||||
import textwrap
|
import textwrap
|
||||||
@@ -158,17 +159,25 @@ def prepare_docstring(s):
|
|||||||
of nested_parse().) An empty line is added to act as a separator between
|
of nested_parse().) An empty line is added to act as a separator between
|
||||||
this docstring and following content.
|
this docstring and following content.
|
||||||
"""
|
"""
|
||||||
if not s or s.isspace():
|
lines = s.expandtabs().splitlines()
|
||||||
return ['']
|
# Find minimum indentation of any non-blank lines after first line.
|
||||||
s = s.expandtabs()
|
margin = sys.maxint
|
||||||
nl = s.rstrip().find('\n')
|
for line in lines[1:]:
|
||||||
if nl == -1:
|
content = len(line.lstrip())
|
||||||
# Only one line...
|
if content:
|
||||||
return [s.strip(), '']
|
indent = len(line) - content
|
||||||
# The first line may be indented differently...
|
margin = min(margin, indent)
|
||||||
firstline = s[:nl].strip()
|
# Remove indentation.
|
||||||
otherlines = textwrap.dedent(s[nl+1:])
|
if lines:
|
||||||
return [firstline] + otherlines.splitlines() + ['']
|
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):
|
def get_module_charset(module):
|
||||||
@@ -441,8 +450,8 @@ def generate_rst(what, name, members, options, add_content, document, lineno,
|
|||||||
# unqualified :members: given
|
# unqualified :members: given
|
||||||
if what == 'module':
|
if what == 'module':
|
||||||
# for implicit module members, check __module__ to avoid documenting
|
# for implicit module members, check __module__ to avoid documenting
|
||||||
# imported objects
|
# imported objects if __all__ is not defined
|
||||||
members_check_module = True
|
members_check_module = not hasattr(todoc, '__all__')
|
||||||
all_members = inspect.getmembers(todoc)
|
all_members = inspect.getmembers(todoc)
|
||||||
else:
|
else:
|
||||||
if options.inherited_members:
|
if options.inherited_members:
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class HTMLTranslator(BaseTranslator):
|
|||||||
if node.parent['desctype'] in ('class', 'exception'):
|
if node.parent['desctype'] in ('class', 'exception'):
|
||||||
self.body.append('%s ' % node.parent['desctype'])
|
self.body.append('%s ' % node.parent['desctype'])
|
||||||
def depart_desc_signature(self, node):
|
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] +
|
self.body.append(u'<a class="headerlink" href="#%s" ' % node['ids'][0] +
|
||||||
u'title="Permalink to this definition">\u00B6</a>')
|
u'title="Permalink to this definition">\u00B6</a>')
|
||||||
self.body.append('</dt>\n')
|
self.body.append('</dt>\n')
|
||||||
@@ -342,7 +342,7 @@ class HTMLTranslator(BaseTranslator):
|
|||||||
|
|
||||||
def depart_title(self, node):
|
def depart_title(self, node):
|
||||||
close_tag = self.context[-1]
|
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('</h') or
|
||||||
close_tag.startswith('</a></h')) and \
|
close_tag.startswith('</a></h')) and \
|
||||||
node.parent.hasattr('ids') and node.parent['ids']:
|
node.parent.hasattr('ids') and node.parent['ids']:
|
||||||
|
|||||||
Reference in New Issue
Block a user