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

Fix bug of Sphinx's .. code:: directive not recognizing :class: option #9688

Merged

Conversation

latosha-maltba
Copy link
Contributor

Subject: Fix bug of Sphinx's .. code:: directive not recognizing :class: option

Feature or Bugfix

  • Bugfix

Purpose

Sphinx's own .. code:: directive (but not docutils') does not recognise
the :class: option but only the :classes: option. This is probably due
to an oversight that the user-visible option is called :class: while
the Python attribute is called classes (to not collide with the
keyword class).

Fix it by checking for the option class instead of classes.

Remark: Theoretically, someone could depend on classes being
recognised by Sphinx's .. code:: directive. However, I highly
doubt that because:

a) class is the canonical and documented way to add classes
b) classes was never documented by Sphinx.
c) Sphinx encourages .. code-block:: over .. code::.

@astrojuanlu
Copy link
Contributor

Thanks for the PR @latosha-maltba ! Looks like it has conflicts though. Perhaps you branched off master, but this is being merged in 4.x instead?

@latosha-maltba
Copy link
Contributor Author

Hi, @astrojuanlu

Thanks for the PR @latosha-maltba ! Looks like it has conflicts though. Perhaps you branched off master, but this is being merged in 4.x instead?

Not quite, there was just some other pull request merged and that lead to a conflict in CHANGES as is to expect when documenting the changelog in a monolithic file.

Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you call docutils.parsers.rst.roles.set_classes() before accessing self.options['classes']? It's a well-known technique to implement directives on docutils. This is a bug that the code directive does not call the helper function before accessing the option. You can see examples under the docutils.parsers.rst.directives package.

CHANGES Outdated
@@ -41,6 +41,7 @@ Bugs fixed
* #9649: HTML search: when objects have the same name but in different domains,
return all of them as result instead of just one.
* #9678: linkcheck: file extension was shown twice in warnings
* Fix bug ``.. code::`` not recognising ``:classes:`` option instead of ``:class:`` option. The new behaviour is only to accept ``:class:``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. The code directive does not recognize the :classes: option. Simply, it ignores given :class: option.

@tk0miya tk0miya added this to the 4.3.0 milestone Oct 3, 2021
Sphinx's own .. code:: directive (but not docutils') does not recognise
the :class: option but only the :classes: option.  This is probably due
to an oversight that the user-visible option is called ``:class:`` while
the Python attribute is called ``classes`` (to not collide with the
keyword ``class``).

Fix it by checking for the option ``class`` instead of ``classes``.
@latosha-maltba
Copy link
Contributor Author

Been there, done that.

@tk0miya tk0miya merged commit 15df183 into sphinx-doc:4.x Oct 9, 2021
@tk0miya
Copy link
Member

tk0miya commented Oct 9, 2021

Merged! Thank you for your work :-)

tk0miya added a commit that referenced this pull request Oct 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants