Skip to content

Commit 432bc5e

Browse files
timhoffmAA-Turner
andauthored
Add a class option to the autosummary directive (#13144)
Co-authored-by: Adam Turner <[email protected]>
1 parent e65bbb9 commit 432bc5e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Features added
2424
* #11824: linkcode: Allow extensions to add support for a domain by defining
2525
the keys that should be present.
2626
Patch by Nicolas Peugnet.
27+
* #13144: Add a ``class`` option to the :rst:dir:`autosummary` directive.
28+
Patch by Tim Hoffmann.
2729

2830
Bugs fixed
2931
----------

doc/usage/extensions/autosummary.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ The :mod:`sphinx.ext.autosummary` extension does this in two parts:
6363

6464
.. rubric:: Options
6565

66+
.. rst:directive:option:: class: class names
67+
:type: a list of class names, separated by spaces
68+
69+
Assign `class attributes`_ to the table.
70+
This is a :dudir:`common option <common-options>`.
71+
72+
.. _class attributes: https://docutils.sourceforge.io/docs/ref/doctree.html#classes
73+
74+
.. versionadded:: 8.2
75+
6676
.. rst:directive:option:: toctree: optional directory name
6777
6878
If you want the :rst:dir:`autosummary` table to also serve as a

sphinx/ext/autosummary/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class Autosummary(SphinxDirective):
234234
has_content = True
235235
option_spec: ClassVar[OptionSpec] = {
236236
'caption': directives.unchanged_required,
237+
'class': directives.class_option,
237238
'toctree': directives.unchanged,
238239
'nosignatures': directives.flag,
239240
'recursive': directives.flag,
@@ -431,7 +432,9 @@ def get_table(self, items: list[tuple[str, str, str, str]]) -> list[Node]:
431432
table_spec['spec'] = r'\X{1}{2}\X{1}{2}'
432433

433434
table = autosummary_table('')
434-
real_table = nodes.table('', classes=['autosummary longtable'])
435+
real_table = nodes.table(
436+
'', classes=['autosummary', 'longtable', *self.options.get('class', ())]
437+
)
435438
table.append(real_table)
436439
group = nodes.tgroup('', cols=2)
437440
real_table.append(group)

0 commit comments

Comments
 (0)