Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heading in only directive gets displaced #12899

Open
jdoubleu opened this issue Sep 18, 2024 · 0 comments
Open

Heading in only directive gets displaced #12899

jdoubleu opened this issue Sep 18, 2024 · 0 comments

Comments

@jdoubleu
Copy link

jdoubleu commented Sep 18, 2024

Describe the bug

When including a heading inside the .. only:: directive, it is somehow reordered.

Expected output:

  1. H's
    1. Subheading
      1. <text>
    2. References
      1. <citations>
      2. <text>

Actual output:
image

As you can see, the References header is shown after the citations and even the paragraph.

When trying to reproduce this issue, I noticed, that it only works if there is another heading of the same level before the .. only:: directive.

How to Reproduce

index.rst:

####################################
Sphinx Bug Heading In Only Directive
####################################
   
Reproduction of the bug.

H's
===

Subheading
----------

This is a subheading.

.. only:: html

   References
   ----------

   This paragraph is only displayed when generating the HTML output.

.. [CIT] Example citation

This paragraph should be shown *after* the "References" header [CIT]_.

P's
===

.. only:: html

   On the other hand, whenever the :code:`only` directive does **not** include a heading, the order is as expected.

This paragraph is shown after the above, at least for HTML output.

Environment Information

Platform:              win32; (Windows-10-10.0.22631-SP0)
Python version:        3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)])
Python implementation: CPython
Sphinx version:        8.0.2
Docutils version:      0.21.2
Jinja2 version:        3.1.4
Pygments version:      2.18.0

Sphinx extensions

[]

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants