Skip to content

Commit 1f282c6

Browse files
committed
Fix a case where content under admonitions weren't dettabbed properly
1 parent 49e1d29 commit 1f282c6

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

docs/change_log/release-3.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ The following bug fixes are included in the 3.3 release:
101101
* Fix unescaping of HTML characters `<>` in CodeHilite (#990).
102102
* Fix complex scenarios involving lists and admonitions (#1004).
103103
* Fix complex scenarios with nested ordered and unordered lists in a definition list (#918).
104+
* Fix corner cases with lists under admonitions.
104105

105106
[spec]: https://www.w3.org/TR/html5/text-level-semantics.html#the-code-element
106107
[fenced_code]: ../extensions/fenced_code_blocks.md

markdown/blockprocessors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ def lastChild(self, parent):
7878
else:
7979
return None
8080

81-
def detab(self, text):
81+
def detab(self, text, length=None):
8282
""" Remove a tab from the front of each line of the given text. """
83+
if length is None:
84+
length = self.tab_length
8385
newtext = []
8486
lines = text.split('\n')
8587
for line in lines:
86-
if line.startswith(' '*self.tab_length):
87-
newtext.append(line[self.tab_length:])
88+
if line.startswith(' ' * length):
89+
newtext.append(line[length:])
8890
elif not line.strip():
8991
newtext.append('')
9092
else:

markdown/extensions/admonition.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,24 @@ def __init__(self, parser):
4848
self.current_sibling = None
4949
self.content_indention = 0
5050

51-
def get_sibling(self, parent, block):
51+
def parse_content(self, parent, block):
5252
"""Get sibling admontion.
5353
5454
Retrieve the appropriate siblimg element. This can get trickly when
5555
dealing with lists.
5656
5757
"""
5858

59+
old_block = block
60+
the_rest = ''
61+
5962
# We already acquired the block via test
6063
if self.current_sibling is not None:
6164
sibling = self.current_sibling
62-
block = block[self.content_indent:]
65+
block, the_rest = self.detab(block, self.content_indent)
6366
self.current_sibling = None
6467
self.content_indent = 0
65-
return sibling, block
68+
return sibling, block, the_rest
6669

6770
sibling = self.lastChild(parent)
6871

@@ -96,17 +99,19 @@ def get_sibling(self, parent, block):
9699
sibling = None
97100

98101
if sibling is not None:
102+
indent += self.tab_length
103+
block, the_rest = self.detab(old_block, indent)
99104
self.current_sibling = sibling
100105
self.content_indent = indent
101106

102-
return sibling, block
107+
return sibling, block, the_rest
103108

104109
def test(self, parent, block):
105110

106111
if self.RE.search(block):
107112
return True
108113
else:
109-
return self.get_sibling(parent, block)[0] is not None
114+
return self.parse_content(parent, block)[0] is not None
110115

111116
def run(self, parent, blocks):
112117
block = blocks.pop(0)
@@ -116,10 +121,9 @@ def run(self, parent, blocks):
116121
if m.start() > 0:
117122
self.parser.parseBlocks(parent, [block[:m.start()]])
118123
block = block[m.end():] # removes the first line
124+
block, theRest = self.detab(block)
119125
else:
120-
sibling, block = self.get_sibling(parent, block)
121-
122-
block, theRest = self.detab(block)
126+
sibling, block, theRest = self.parse_content(parent, block)
123127

124128
if m:
125129
klass, title = self.get_class_and_title(m)

tests/test_syntax/extensions/test_admonition.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,33 @@ def test_with_preceding_text(self):
213213
),
214214
extensions=['admonition']
215215
)
216+
217+
def test_admontion_detabbing(self):
218+
self.assertMarkdownRenders(
219+
self.dedent(
220+
'''
221+
!!! note "Admonition"
222+
- Parent 1
223+
224+
- Child 1
225+
- Child 2
226+
'''
227+
),
228+
self.dedent(
229+
'''
230+
<div class="admonition note">
231+
<p class="admonition-title">Admontion</p>
232+
<ul>
233+
<li>
234+
<p>Parent 1</p>
235+
<ul>
236+
<li>Child 1</li>
237+
<li>Child 2</li>
238+
</ul>
239+
</li>
240+
</ul>
241+
</div>
242+
'''
243+
),
244+
extensions=['admonition']
245+
)

0 commit comments

Comments
 (0)