Georg Brandl avatar Georg Brandl committed e12c783

Fixes #873: do not raise assertion errors on empty "only" directives.

Comments (0)

Files changed (2)

 * #892: Fix single-HTML builder misbehaving with the master document in a
   subdirectory.
 
+* #873: Fix assertion errors with empty ``only`` directives.
+
 
 Release 1.1.2 (Nov 1, 2011) -- 1.1.1 is a silly version number anyway!
 ======================================================================

sphinx/environment.py

         self.warn_node(msg % {'target': target}, node)
 
     def process_only_nodes(self, doctree, builder, fromdocname=None):
+        # A comment on the comment() nodes being inserted: replacing by [] would
+        # result in a "Losing ids" exception if there is a target node before
+        # the only node, so we make sure docutils can transfer the id to
+        # something, even if it's just a comment and will lose the id anyway...
         for node in doctree.traverse(addnodes.only):
             try:
                 ret = builder.tags.eval_condition(node['expr'])
             except Exception, err:
                 self.warn_node('exception while evaluating only '
                                'directive expression: %s' % err, node)
-                node.replace_self(node.children)
+                node.replace_self(node.children or nodes.comment())
             else:
                 if ret:
-                    node.replace_self(node.children)
+                    node.replace_self(node.children or nodes.comment())
                 else:
-                    # replacing by [] would result in an "Losing ids" exception
-                    # if there is a target node before the only node
                     node.replace_self(nodes.comment())
 
     def assign_section_numbers(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.