summaryrefslogtreecommitdiff
path: root/sphinx
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-10-28 18:13:40 +0100
committerGeorg Brandl <georg@python.org>2012-10-28 18:13:40 +0100
commitc88872a5fa4b551aef342bf17e2ecc1212f8a622 (patch)
treeaa9133c34dd1c819ef0b8d91d038add2125fabea /sphinx
parent11c8d7368a158bba50eeb5d85e7be9cc60a310de (diff)
parent0f043f68a08f0a93da6dc4c07b215a5ae7b8680d (diff)
downloadsphinx-c88872a5fa4b551aef342bf17e2ecc1212f8a622.tar.gz
Merged in macfreek/sphinx/stable (pull request #59)
Diffstat (limited to 'sphinx')
-rw-r--r--sphinx/builders/html.py3
-rw-r--r--sphinx/directives/other.py43
-rw-r--r--sphinx/environment.py1
-rw-r--r--sphinx/ext/autodoc.py5
-rw-r--r--sphinx/ext/graphviz.py4
-rw-r--r--sphinx/highlighting.py2
-rw-r--r--sphinx/writers/latex.py3
7 files changed, 53 insertions, 8 deletions
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 81840374..f5218673 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -610,7 +610,8 @@ class StandaloneHTMLBuilder(Builder):
"""
Builder.post_process_images(self, doctree)
for node in doctree.traverse(nodes.image):
- if not node.has_key('scale') or \
+ scale_keys = ('scale', 'width', 'height')
+ if not any((key in node) for key in scale_keys) or \
isinstance(node.parent, nodes.reference):
# docutils does unfortunately not preserve the
# ``target`` attribute on images, so we need to check
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py
index aa4142d6..506d4be9 100644
--- a/sphinx/directives/other.py
+++ b/sphinx/directives/other.py
@@ -338,9 +338,46 @@ class Only(Directive):
node.document = self.state.document
set_source_info(self, node)
node['expr'] = self.arguments[0]
- self.state.nested_parse(self.content, self.content_offset, node,
- match_titles=1)
- return [node]
+
+ # Same as util.nested_parse_with_titles but try to handle nested
+ # sections which should be raised higher up the doctree.
+ surrounding_title_styles = self.state.memo.title_styles
+ surrounding_section_level = self.state.memo.section_level
+ self.state.memo.title_styles = []
+ self.state.memo.section_level = 0
+ try:
+ result = self.state.nested_parse(self.content, self.content_offset,
+ node, match_titles=1)
+ title_styles = self.state.memo.title_styles
+ if (not surrounding_title_styles
+ or not title_styles
+ or title_styles[0] not in surrounding_title_styles
+ or not self.state.parent):
+ # No nested sections so no special handling needed.
+ return [node]
+ # Calculate the depths of the current and nested sections.
+ current_depth = 0
+ parent = self.state.parent
+ while parent:
+ current_depth += 1
+ parent = parent.parent
+ current_depth -= 2
+ title_style = title_styles[0]
+ nested_depth = len(surrounding_title_styles)
+ if title_style in surrounding_title_styles:
+ nested_depth = surrounding_title_styles.index(title_style)
+ # Use these depths to determine where the nested sections should
+ # be placed in the doctree.
+ n_sects_to_raise = current_depth - nested_depth + 1
+ parent = self.state.parent
+ for i in xrange(n_sects_to_raise):
+ if parent.parent:
+ parent = parent.parent
+ parent.append(node)
+ return []
+ finally:
+ self.state.memo.title_styles = surrounding_title_styles
+ self.state.memo.section_level = surrounding_section_level
class Include(BaseInclude):
diff --git a/sphinx/environment.py b/sphinx/environment.py
index a4bbbe3b..824d9c18 100644
--- a/sphinx/environment.py
+++ b/sphinx/environment.py
@@ -66,6 +66,7 @@ default_settings = {
'doctitle_xform': False,
'sectsubtitle_xform': False,
'halt_level': 5,
+ 'file_insertion_enabled': True,
}
# This is increased every time an environment attribute is added
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index 9c6575f5..c15726b4 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -862,7 +862,7 @@ class DocstringSignatureMixin(object):
"""
def _find_signature(self, encoding=None):
- docstrings = Documenter.get_doc(self, encoding, 2)
+ docstrings = Documenter.get_doc(self, encoding)
if len(docstrings) != 1:
return
doclines = docstrings[0]
@@ -877,6 +877,9 @@ class DocstringSignatureMixin(object):
# the base name must match ours
if not self.objpath or base != self.objpath[-1]:
return
+ # re-prepare docstring to ignore indentation after signature
+ docstrings = Documenter.get_doc(self, encoding, 2)
+ doclines = docstrings[0]
# ok, now jump over remaining empty lines and set the remaining
# lines as the new doclines
i = 1
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py
index 4e72761e..bacd7248 100644
--- a/sphinx/ext/graphviz.py
+++ b/sphinx/ext/graphviz.py
@@ -229,10 +229,10 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
(fname, alt, imgcss))
else:
# has a map: get the name of the map and connect the parts
- mapname = mapname_re.match(imgmap[0]).group(1)
+ mapname = mapname_re.match(imgmap[0].decode('utf-8')).group(1)
self.body.append('<img src="%s" alt="%s" usemap="#%s" %s/>\n' %
(fname, alt, mapname, imgcss))
- self.body.extend(imgmap)
+ self.body.extend([item.decode('utf-8') for item in imgmap])
if node.get('caption') and not inline:
self.body.append('</p>\n<p class="caption">')
self.body.append(self.encode(node['caption']))
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py
index 2f61c1ef..63464914 100644
--- a/sphinx/highlighting.py
+++ b/sphinx/highlighting.py
@@ -207,6 +207,8 @@ class PygmentsBridge(object):
if self.dest == 'html':
return hlsource
else:
+ if not isinstance(hlsource, unicode): # Py2 / Pygments < 1.6
+ hlsource = hlsource.decode()
return hlsource.translate(tex_hl_escape_map_new)
except ErrorToken:
# this is most probably not the selected language,
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index f2ebad36..e5ef3a61 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -100,7 +100,8 @@ class LaTeXWriter(writers.Writer):
class ExtBabel(Babel):
def get_shorthandoff(self):
shortlang = self.language.split('_')[0]
- if shortlang in ('de', 'sl', 'pt', 'es', 'nl', 'pl', 'it'):
+ if shortlang in ('de', 'ngerman', 'sl', 'slovene', 'pt', 'portuges', 'es', 'spanish',
+ 'nl', 'dutch', 'pl', 'polish', 'it', 'italian'):
return '\\shorthandoff{"}'
return ''