diff options
-rw-r--r-- | markdown/extensions/def_list.py | 14 | ||||
-rw-r--r-- | tests/extensions/extra/def-in-list.html | 25 | ||||
-rw-r--r-- | tests/extensions/extra/def-in-list.txt | 15 |
3 files changed, 50 insertions, 4 deletions
diff --git a/markdown/extensions/def_list.py b/markdown/extensions/def_list.py index da1726a..382445c 100644 --- a/markdown/extensions/def_list.py +++ b/markdown/extensions/def_list.py @@ -34,10 +34,11 @@ class DefListProcessor(markdown.blockprocessors.BlockProcessor): return bool(self.RE.search(block)) def run(self, parent, blocks): - block = blocks.pop(0) - m = self.RE.search(block) - terms = [l.strip() for l in block[:m.start()].split('\n') if l.strip()] - block = block[m.end():] + + raw_block = blocks.pop(0) + m = self.RE.search(raw_block) + terms = [l.strip() for l in raw_block[:m.start()].split('\n') if l.strip()] + block = raw_block[m.end():] no_indent = self.NO_INDENT_RE.match(block) if no_indent: d, theRest = (block, None) @@ -48,6 +49,11 @@ class DefListProcessor(markdown.blockprocessors.BlockProcessor): else: d = m.group(2) sibling = self.lastChild(parent) + if not terms and sibling is None: + # This is not a definition item. Most likely a paragraph that + # starts with a colon at the begining of a document or list. + blocks.insert(0, raw_block) + return False if not terms and sibling.tag == 'p': # The previous paragraph contains the terms state = 'looselist' diff --git a/tests/extensions/extra/def-in-list.html b/tests/extensions/extra/def-in-list.html new file mode 100644 index 0000000..21cddaa --- /dev/null +++ b/tests/extensions/extra/def-in-list.html @@ -0,0 +1,25 @@ +<p>: a paragraph that starts with a colon</p> +<ul> +<li>A List item</li> +<li> +<dl> +<dt>A def term</dt> +<dd>A def item</dd> +<dd>a second</dd> +</dl> +</li> +<li> +<dl> +<dt>Another def term</dt> +<dd> +<p>a loose item</p> +</dd> +<dd> +<p>a second</p> +</dd> +</dl> +</li> +<li> +<p>: a list item that starts with a colon</p> +</li> +</ul>
\ No newline at end of file diff --git a/tests/extensions/extra/def-in-list.txt b/tests/extensions/extra/def-in-list.txt new file mode 100644 index 0000000..7a292ab --- /dev/null +++ b/tests/extensions/extra/def-in-list.txt @@ -0,0 +1,15 @@ +: a paragraph that starts with a colon + +* A List item +* + A def term + : A def item + : a second + +* Another def term + + : a loose item + + : a second + +* : a list item that starts with a colon |