Issues

Issue #1420 new

Only directive does not exclude content from index (or doctrees)

Anonymous created an issue

I'm documenting a multi-programming language API using Sphinx. I have the project setup so that it has "master" pages that use the only directive to pull in the correct content, i.e:

.. only:: java

   .. doxygenclass:: com::leapmotion::leap::Frame
      :project: java
      :members:
      :sections: public-func, property, public-static-func

.. only:: python

   .. include:: ../fragments/python/Leap.Frame.rst

.. only:: javascript

   .. include:: ../fragments/javascript/Leap.Frame.rst

This works to properly select the correct content, but when a search is executed using the HTML output search function, Python results are included no matter what the tag controlling the only directive is set to:

Leap.Frame.current_frames_per_second (Python attribute, in Frame)
Leap.Controller.POLICY_BACKGROUND_FRAMES (Python data, in Controller)

Likewise, using only with toctree doesn't work, all toctree directives are included

.. only:: python

   .. toctree::
      :hidden:

   Leap.Listener
   Leap.Matrix

.. only:: javascript

   .. toctree::
      :hidden:

      Leap.CircleGesture
      Leap.Config

So it seems that even though the rat content is excluded from the output, other facets of the content are not properly excluded.

A discussion of the same/related problems: https://groups.google.com/forum/#!topic/sphinx-users/Zrh7T5y4FVY

My docs as Html for more examples: https://developer.leapmotion.com/documentation/python/index.html

Comments (2)

  1. David Beitey

    I'm experiencing the same (or very similar) issue with toctrees. I'm using this structure:

    .. only:: user
    
       .. toctree::
    
          main
          features
          glossary
    
    
    .. only:: admin
    
       .. toctree::
    
          main
          administration
          technical
          glossary
    

    and all content gets included in the output, irrespective of the tag applied.

    I'd like to be able to switch the main toctree in my index.rst file based upon tags and have only the applicable toctree used. The actual page rendering works, but issues include:

    1. All content is included in the output, meaning it is thus searchable.
    2. A sidebar (which is generated using the _get_local_toctree function for builders/html.py) sees the only condition ignored when the docutils nodes are being traversed. Essentially, the toctree() function is called in a Jinja template, and eventually, the traverse() and _fast_traverse() methods on the sphinx.addnodes.only nodes are called, but do not apply any conditional checks to the nodes these functions return.
  2. Log in to comment