Skip to content

Commit

Permalink
Add a class option to the autosummary directive
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm committed Nov 19, 2024
1 parent 80ed1b4 commit 841f9c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Deprecated

Features added
--------------
* #13144: Add a ``class`` option to the :rst:dir:`autosummary` directive.
Patch by Tim Hoffmann.

Bugs fixed
----------
Expand Down
11 changes: 11 additions & 0 deletions doc/usage/extensions/autosummary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The :mod:`sphinx.ext.autosummary` extension does this in two parts:
.. currentmodule:: sphinx

.. autosummary::
:toctree:

environment.BuildEnvironment
util.relative_uri
Expand All @@ -63,6 +64,16 @@ The :mod:`sphinx.ext.autosummary` extension does this in two parts:

.. rubric:: Options

.. rst:directive:option:: class: class names
:type: a list of class names, separated by spaces
Assign `class attributes`_ to the table.
This is a :dudir:`common option <common-options>`.
.. _class attributes: https://docutils.sourceforge.io/docs/ref/doctree.html#classes
.. versionadded:: 8.2
.. rst:directive:option:: toctree: optional directory name
If you want the :rst:dir:`autosummary` table to also serve as a
Expand Down
3 changes: 2 additions & 1 deletion sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class Autosummary(SphinxDirective):
has_content = True
option_spec: ClassVar[OptionSpec] = {
'caption': directives.unchanged_required,
'class': directives.class_option,
'toctree': directives.unchanged,
'nosignatures': directives.flag,
'recursive': directives.flag,
Expand Down Expand Up @@ -397,7 +398,7 @@ def get_table(self, items: list[tuple[str, str, str, str]]) -> list[Node]:
table_spec['spec'] = r'\X{1}{2}\X{1}{2}'

table = autosummary_table('')
real_table = nodes.table('', classes=['autosummary longtable'])
real_table = nodes.table('', classes=['autosummary', 'longtable', *self.options.get('class', ())])

Check failure on line 401 in sphinx/ext/autosummary/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sphinx/ext/autosummary/__init__.py:401:96: E501 Line too long (106 > 95)
table.append(real_table)
group = nodes.tgroup('', cols=2)
real_table.append(group)
Expand Down

0 comments on commit 841f9c0

Please sign in to comment.