Skip to content

Commit

Permalink
Include summary line
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jun 6, 2022
1 parent 772ba7e commit f40cf8c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions doc/usage/restructuredtext/directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,8 @@ Using collapsible content
This is the body of the directive.

Only the HTML 5 output format supports collapsible content. For other builders,
the body of the directive is rendered in the document and the *summary
description* text is ignored.
the *summary description* text and the body of the directive are rendered in
the document.

.. versionadded:: 5.1

Expand Down
2 changes: 1 addition & 1 deletion sphinx/directives/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def run(self) -> List[Node]:
if len(self.arguments) > 0:
summary = self.arguments[0].strip()
else:
summary = "Collapsed Content"
summary = "Collapsed Content:"

# parse the argument as reST
summary_trimmed = self._prepare_argument_string(summary)
Expand Down
6 changes: 3 additions & 3 deletions sphinx/util/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ def process_collapsible_nodes(document: Node, builder_name: str) -> None:
# result in a "Losing ids" exception if there is a target node before
# the only node, so we make sure docutils can transfer the id to
# something, even if it's just a comment and will lose the id anyway...
# Slicing node.children removes the first element, which will always
# be a collapsible_summary node.
node.replace_self(node.children[1:] or nodes.comment())
children = node.children
children[0] = nodes.paragraph("", "", *children[0].children) # type: ignore
node.replace_self(children or nodes.comment())


def _new_copy(self: Element) -> Element:
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-directive-collapsible/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Collapsible directive tests

Default section summary line

.. collapsible:: Custom summary line for the collapsible content
.. collapsible:: Custom summary line for the collapsible content:

Collapsible sections can also have custom summary lines

Expand Down
18 changes: 15 additions & 3 deletions tests/test_directive_collapsible.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ def test_non_html(app, status, warning):
Collapsible directive tests
***************************
Collapsed Content:
Default section summary line
Custom summary line for the collapsible content:
Collapsible sections can also have custom summary lines
Collapsed Content:
Collapsible sections can have normal reST content such as **bold** and
*emphasised* text, and also links!
Collapsed Content:
Collapsible sections can have sections:
Expand All @@ -30,6 +38,10 @@ def test_non_html(app, status, warning):
Some words within a section, as opposed to outwith the section.
Summary text here with **bold** and *em* and a **RFC 2324** reference!
That was a newline in the reST source! We can also have links and more
links.
This is some text!
"""

Expand All @@ -47,9 +59,9 @@ def test_html(app, status, warning):
assert isinstance(collapsible_nodes[3][0], addnodes.collapsible_summary)
assert isinstance(collapsible_nodes[4][0], addnodes.collapsible_summary)

assert collapsible_nodes[0][0].astext() == 'Collapsed Content'
assert collapsible_nodes[2][0].astext() == 'Collapsed Content'
assert collapsible_nodes[3][0].astext() == 'Collapsed Content'
assert collapsible_nodes[0][0].astext() == 'Collapsed Content:'
assert collapsible_nodes[2][0].astext() == 'Collapsed Content:'
assert collapsible_nodes[3][0].astext() == 'Collapsed Content:'

assert isinstance(collapsible_nodes[3][2], nodes.section)

Expand Down

0 comments on commit f40cf8c

Please sign in to comment.