Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pymdownx/blocks/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re

RE_SEP = re.compile(r'[_-]+')
RE_HEADING = re.compile(r'^(?P<level>#{1,6})(?P<header>(?:\\.|[^\\])*?)#*$')


class Details(Block):
Expand Down Expand Up @@ -81,7 +82,12 @@ def on_create(self, parent):
# Create the summary
if summary is not None:
s = etree.SubElement(el, 'summary')
s.text = summary
m = RE_HEADING.match(summary)
if m:
h = etree.SubElement(s, f'h{len(m.group('level'))}')
h.text = m.group('header').strip()
else:
s.text = summary

return el

Expand Down
20 changes: 20 additions & 0 deletions tests/test_extensions/test_blocks/test_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ def test_type_empty_title(self):
True
)

def test_heading_in_title(self):
"""Test details with heading in title."""

self.check_markdown(
R'''
/// details | ## A Title
Some *content*
///
''',
r'''
<details>
<summary>
<h2>A Title</h2>
</summary>
<p>Some <em>content</em></p>
</details>
''',
True
)

def test_details(self):
"""Test details with title."""

Expand Down