Skip to content

Commit c704cf5

Browse files
committed
Add a class option to the autosummary directive
1 parent 80ed1b4 commit c704cf5

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Deprecated
1717

1818
Features added
1919
--------------
20+
* #13144: Add a ``class`` option to the :rst:dir:`autosummary` directive.
21+
Patch by Tim Hoffmann.
2022

2123
Bugs fixed
2224
----------

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ class Autosummary(SphinxDirective):
224224
has_content = True
225225
option_spec: ClassVar[OptionSpec] = {
226226
'caption': directives.unchanged_required,
227+
'class': directives.class_option,
227228
'toctree': directives.unchanged,
228229
'nosignatures': directives.flag,
229230
'recursive': directives.flag,
@@ -397,7 +398,7 @@ def get_table(self, items: list[tuple[str, str, str, str]]) -> list[Node]:
397398
table_spec['spec'] = r'\X{1}{2}\X{1}{2}'
398399

399400
table = autosummary_table('')
400-
real_table = nodes.table('', classes=['autosummary longtable'])
401+
real_table = nodes.table('', classes=['autosummary', 'longtable', *self.options.get('class', ())])
401402
table.append(real_table)
402403
group = nodes.tgroup('', cols=2)
403404
real_table.append(group)

0 commit comments

Comments
 (0)