Add a class option to the autosummary directive (#13144)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
Tim Hoffmann
2025-01-04 01:28:59 +01:00
committed by GitHub
parent e65bbb96ae
commit 432bc5e50b
3 changed files with 16 additions and 1 deletions

View File

@@ -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
----------

View File

@@ -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

View File

@@ -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,
@@ -431,7 +432,9 @@ class Autosummary(SphinxDirective):
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)