diff --git a/pymdownx/blocks/details.py b/pymdownx/blocks/details.py index 586772344..99e8c89c6 100644 --- a/pymdownx/blocks/details.py +++ b/pymdownx/blocks/details.py @@ -5,6 +5,7 @@ import re RE_SEP = re.compile(r'[_-]+') +RE_HEADING = re.compile(r'^(?P#{1,6})(?P
(?:\\.|[^\\])*?)#*$') class Details(Block): @@ -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 diff --git a/tests/test_extensions/test_blocks/test_details.py b/tests/test_extensions/test_blocks/test_details.py index 206041b4c..81fdc90a5 100644 --- a/tests/test_extensions/test_blocks/test_details.py +++ b/tests/test_extensions/test_blocks/test_details.py @@ -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''' +
+ +

A Title

+
+

Some content

+
+ ''', + True + ) + def test_details(self): """Test details with title."""