Skip to content

Commit

Permalink
Add a class option to the autosummary directive (#13144)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <[email protected]>
  • Loading branch information
timhoffm and AA-Turner authored Jan 4, 2025
1 parent e65bbb9 commit 432bc5e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Features added
* #11824: linkcode: Allow extensions to add support for a domain by defining
the keys that should be present.
Patch by Nicolas Peugnet.
* #13144: Add a ``class`` option to the :rst:dir:`autosummary` directive.
Patch by Tim Hoffmann.

Bugs fixed
----------
Expand Down
10 changes: 10 additions & 0 deletions doc/usage/extensions/autosummary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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
5 changes: 4 additions & 1 deletion sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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 @@ -431,7 +432,9 @@ 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', ())]
)
table.append(real_table)
group = nodes.tgroup('', cols=2)
real_table.append(group)
Expand Down

0 comments on commit 432bc5e

Please sign in to comment.