sphinx-doc / sphinx-doc/sphinx

Broken HTML rendering of index entry that contains a semicolon

Open
#8,904 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug type:enhancement
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
I'm generating documentation for a Prolog system implementation using Sphinx. The Prolog language includes conjunction and disjunction control constructs that are represented by, respectively, the compound terms (';')/2, (,)/2, and !/0. The index entries for these control constructs must contain this exact text.

But the following index directives don't generate correct entries due to the presence of the comma, semicolon, and exclamation mark:

.. index:: (;)/2

.. index:: (',')/2

.. index:: !/0

For the first two cases, a solution was mentioned in StackOverflow related question (https://stackoverflow.com/questions/66229133/escaping-special-characters-in-index-directives) :

.. index:: single: (',')/2

.. index:: single: !/0

But this solution doesn't work for the (';')/2. Instead, I get (using the HTML render):

      <li>
    (

      <ul>
        <li><a href="my_index.html#index-1">)/2</a>
</li>
      </ul></li>

Also tried to use a backslash for escaping the semicolon to no avail. As mentioned in the SO answer, the use of single: work if the text that follows consists only of the semicolon.

To Reproduce
The bug handling text that include a semicolon as an index entry can be reproduced using either:

.. index:: (;)/2

or:

.. index:: single: (;)/2

Expected behavior
A well formatted index entry showing as text (';')/2.

Your project
The bug is found in a private company project.

Screenshots
(none)

Environment info

  • OS: macOS 11.2
  • Python version: 3.6.12
  • Sphinx version: v3.4.3
  • Sphinx extensions: (none)
  • Extra tools: (any web browser)

Additional context
StackOverflow related question and answer with further discussion:
https://stackoverflow.com/questions/66229133/escaping-special-characters-in-index-directives

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the two minimal .. index:: directives shown in the report and inspect the generated HTML index. Trace how semicolons are parsed in index entries, then verify that the rendered entry displays the exact text (';')/2 without splitting it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.