From 6049dae6196876e3a306eaa950215fad54f76aee Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 3 Jan 2010 10:27:06 +0100 Subject: [PATCH 1/3] Fix a traceback when the whole module name is stripped by a prefix in modindex_common_prefix. --- sphinx/builders/html.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 0f70932a3..6eff890cf 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -415,6 +415,10 @@ class StandaloneHTMLBuilder(Builder): else: stripped = '' + # we stripped the whole module name + if not mn: + continue + if fl != mn[0].lower() and mn[0] != '_': # heading letter = mn[0].upper() From 0b70a32efedb1d0fe8789e6278db52b0973f1700 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 3 Jan 2010 11:42:15 +0100 Subject: [PATCH 2/3] Ignore images in section titles when generating link captions. (Otherwise, the "alt" text leaks into the caption, and docutils automatically assigns an alt text to images in substitutions.) --- CHANGES | 2 ++ sphinx/environment.py | 10 +++++----- sphinx/util/__init__.py | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index b6a2d3843..177344642 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Release 0.6.4 (in development) ============================== +* Ignore images in section titles when generating link captions. + * #310: support exception messages in the ``testoutput`` blocks of the ``doctest`` extension. diff --git a/sphinx/environment.py b/sphinx/environment.py index 83c97d5f4..b83b2fbf0 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -37,7 +37,7 @@ from docutils.transforms.parts import ContentsFilter from sphinx import addnodes from sphinx.util import movefile, get_matching_docs, SEP, ustrftime, \ - docname_join, FilenameUniqDict, url_re + docname_join, FilenameUniqDict, url_re, clean_astext from sphinx.errors import SphinxError from sphinx.directives import additional_xref_types @@ -820,11 +820,11 @@ class BuildEnvironment: node.line) self.anonlabels[name] = docname, labelid if node.tagname == 'section': - sectname = node[0].astext() # node[0] == title node + sectname = clean_astext(node[0]) # node[0] == title node elif node.tagname == 'figure': for n in node: if n.tagname == 'caption': - sectname = n.astext() + sectname = clean_astext(n) break else: continue @@ -1074,7 +1074,7 @@ class BuildEnvironment: # toctree originates ref = toctreenode['parent'] if not title: - title = self.titles[ref].astext() + title = clean_astext(self.titles[ref]) reference = nodes.reference('', '', refuri=ref, anchorname='', @@ -1222,7 +1222,7 @@ class BuildEnvironment: # reference with explicit title caption = node.astext() else: - caption = self.titles[docname].astext() + caption = clean_astext(self.titles[docname]) innernode = nodes.emphasis(caption, caption) newnode = nodes.reference('', '') newnode['refuri'] = builder.get_relative_uri( diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 3cf58e0ef..59589b6d9 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -442,6 +442,14 @@ def copy_static_entry(source, target, builder, context={}): shutil.copytree(source, target) +def clean_astext(node): + """Like node.astext(), but ignore images.""" + node = node.deepcopy() + for img in node.traverse(docutils.nodes.image): + img['alt'] = '' + return node.astext() + + # monkey-patch Node.traverse to get more speed # traverse() is called so many times during a build that it saves # on average 20-25% overall build time! From b9294de041d1a26afe07c1f43129e58d3afe6f47 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 3 Jan 2010 11:47:46 +0100 Subject: [PATCH 3/3] The ``alt`` text of inheritance diagrams is now much cleaner: it's not the graphviz code but a description "Inheritance diagram of ...". --- CHANGES | 2 ++ sphinx/ext/graphviz.py | 10 ++++++---- sphinx/ext/inheritance_diagram.py | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 177344642..590b91d9c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Release 0.6.4 (in development) ============================== +* The ``alt`` text of inheritance diagrams is now much cleaner. + * Ignore images in section titles when generating link captions. * #310: support exception messages in the ``testoutput`` blocks of diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index 05ec4ec11..d3e1bd99e 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -128,7 +128,8 @@ def render_dot(self, code, options, format, prefix='graphviz'): return relfn, outfn -def render_dot_html(self, node, code, options, prefix='graphviz', imgcls=None): +def render_dot_html(self, node, code, options, prefix='graphviz', + imgcls=None, alt=None): try: fname, outfn = render_dot(self, code, options, 'png', prefix) except GraphvizError, exc: @@ -145,16 +146,17 @@ def render_dot_html(self, node, code, options, prefix='graphviz', imgcls=None): finally: mapfile.close() imgcss = imgcls and 'class="%s"' % imgcls or '' + if alt is None: + alt = self.encode(code).strip() if len(imgmap) == 2: # nothing in image map (the lines are and ) self.body.append('%s\n' % - (fname, self.encode(code).strip(), imgcss)) + (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) self.body.append('%s\n' % - (fname, self.encode(code).strip(), - mapname, imgcss)) + (fname, alt, mapname, imgcss)) self.body.extend(imgmap) self.body.append('

\n') raise nodes.SkipNode diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index b1e945fac..a271e1014 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -301,7 +301,7 @@ class InheritanceDiagram(Directive): node['graph'] = graph # Store the original content for use as a hash node['parts'] = self.options.get('parts', 0) - node['content'] = ' '.join(class_names) + node['content'] = ', '.join(class_names) return [node] @@ -329,7 +329,8 @@ def html_visit_inheritance_diagram(self, node): urls[child['reftitle']] = '#' + child.get('refid') dotcode = graph.generate_dot(name, parts, urls, env=self.builder.env) - render_dot_html(self, node, dotcode, [], 'inheritance', 'inheritance') + render_dot_html(self, node, dotcode, [], 'inheritance', 'inheritance', + alt='Inheritance diagram of ' + node['content']) raise nodes.SkipNode