From dc10661b16b43c12979339d1dc9b0c6a9e638fd1 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:54:39 +0100 Subject: [PATCH 1/2] Add a class option to the autosummary directive --- CHANGES.rst | 2 ++ doc/usage/extensions/autosummary.rst | 10 ++++++++++ sphinx/ext/autosummary/__init__.py | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index ca123d89f43..192abece1d7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,8 @@ Deprecated Features added -------------- +* #13144: Add a ``class`` option to the :rst:dir:`autosummary` directive. + Patch by Tim Hoffmann. Bugs fixed ---------- diff --git a/doc/usage/extensions/autosummary.rst b/doc/usage/extensions/autosummary.rst index 0b2b0c69cf8..117c46a6487 100644 --- a/doc/usage/extensions/autosummary.rst +++ b/doc/usage/extensions/autosummary.rst @@ -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 `. + + .. _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 diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index e77dbe91c79..01804e25455 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -224,6 +224,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, @@ -397,7 +398,8 @@ 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) From f9507430f917998bed59128d3533649e07ef9533 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:05:19 +0000 Subject: [PATCH 2/2] whitespace --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 192abece1d7..651a4a57a6b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,7 @@ Deprecated Features added -------------- + * #13144: Add a ``class`` option to the :rst:dir:`autosummary` directive. Patch by Tim Hoffmann.