Skip to content

Commit

Permalink
Fix empty title handling in admonitions and details (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser authored Nov 10, 2023
1 parent d71f655 commit b896475
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 11 deletions.
5 changes: 5 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 10.4.1

- **FIX**: Block Admonitions: Empty titles should be respected.
- **FIX**: Block Details: Empty summary should be respected.

## 10.4

- **NEW**: Snippets: Allow PathLike objects for `base_path` to better support interactions with MkDocs.
Expand Down
2 changes: 1 addition & 1 deletion pymdownx/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ def parse_version(ver, pre=False):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(10, 4, 0, "final")
__version_info__ = Version(10, 4, 1, "final")
__version__ = __version_info__._get_canonical()
9 changes: 4 additions & 5 deletions pymdownx/blocks/admonition.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ def on_create(self, parent):
el = etree.SubElement(parent, 'div', {'class': ' '.join(classes)})

# Create the title
if not self.argument:
if not atype:
title = None
else:
title = None
if self.argument is None:
if atype:
title = atype.capitalize()
else:
elif self.argument:
title = self.argument

if title is not None:
Expand Down
9 changes: 4 additions & 5 deletions pymdownx/blocks/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ def on_create(self, parent):
el = etree.SubElement(parent, 'details', attributes)

# Create the summary
if not self.argument:
if not dtype:
summary = None
else:
summary = None
if self.argument is None:
if dtype:
summary = dtype.capitalize()
else:
elif self.argument:
summary = self.argument

# Create the summary
Expand Down
20 changes: 20 additions & 0 deletions tests/test_extensions/test_blocks/test_admonitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ def test_type_no_title(self):
True
)

def test_type_empty_title(self):
"""Test test empty title."""

self.check_markdown(
R'''
/// admonition |
type: note
attrs: {class: other}
Some *content*
///
''',
r'''
<div class="admonition note other">
<p>Some <em>content</em></p>
</div>
''',
True
)

def test_admonition(self):
"""Test admonition with title."""

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 @@ -48,6 +48,26 @@ def test_type_no_title(self):
True
)

def test_type_empty_title(self):
"""Test test empty title."""

self.check_markdown(
R'''
/// details |
type: note
attrs: {class: other}
Some *content*
///
''',
r'''
<details class="note other">
<p>Some <em>content</em></p>
</details>
''',
True
)

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

Expand Down

0 comments on commit b896475

Please sign in to comment.