Skip to content

Commit 841f9c0

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

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The :mod:`sphinx.ext.autosummary` extension does this in two parts:
5151
.. currentmodule:: sphinx
5252

5353
.. autosummary::
54+
:toctree:
5455

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

6465
.. rubric:: Options
6566

67+
.. rst:directive:option:: class: class names
68+
:type: a list of class names, separated by spaces
69+
70+
Assign `class attributes`_ to the table.
71+
This is a :dudir:`common option <common-options>`.
72+
73+
.. _class attributes: https://docutils.sourceforge.io/docs/ref/doctree.html#classes
74+
75+
.. versionadded:: 8.2
76+
6677
.. rst:directive:option:: toctree: optional directory name
6778
6879
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)