Skip to content

Commit fd4d1d2

Browse files
committed
Loosen whitespace requirements for admonitions.
Also consume to the end of the first line of any admonition. Everything after the title is discarded. However, the only thing that will match should be whitespace so it should be a non-issue. Fixes #550.
1 parent ab9f4c2 commit fd4d1d2

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

markdown/extensions/admonition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AdmonitionProcessor(BlockProcessor):
4141

4242
CLASSNAME = 'admonition'
4343
CLASSNAME_TITLE = 'admonition-title'
44-
RE = re.compile(r'(?:^|\n)!!!\ ?([\w\-]+)(?:\ "(.*?)")?')
44+
RE = re.compile(r'(?:^|\n)!!! ?([\w\-]+)(?: +"(.*?)")? *(?:\n|$)')
4545

4646
def test(self, parent, block):
4747
sibling = self.lastChild(parent)
@@ -55,7 +55,7 @@ def run(self, parent, blocks):
5555
m = self.RE.search(block)
5656

5757
if m:
58-
block = block[m.end() + 1:] # removes the first line
58+
block = block[m.end():] # removes the first line
5959

6060
block, theRest = self.detab(block)
6161

tests/extensions/admonition.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@
2828
</div>
2929
<div class="admonition tip">
3030
<p>An explicitly empty string prevents the title from being rendered.</p>
31+
</div>
32+
<p>No body:</p>
33+
<div class="admonition note">
34+
<p class="admonition-title">Note</p>
35+
</div>
36+
<p>Extra whitespace after the title should not alter output:</p>
37+
<div class="admonition note">
38+
<p class="admonition-title">Note</p>
3139
</div>

tests/extensions/admonition.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ Not part of an Admonition!
2727

2828
!!! tip ""
2929
An explicitly empty string prevents the title from being rendered.
30+
31+
No body:
32+
33+
!!! note
34+
35+
Extra whitespace after the title should not alter output:
36+
37+
!!! note

0 commit comments

Comments
 (0)