diff options
author | Waylan Limberg <waylan@gmail.com> | 2010-03-19 13:00:35 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2010-03-19 13:00:35 -0400 |
commit | 9a31684b9a683fe9b0d2871649b379fadfb60ade (patch) | |
tree | d8248f52a865f7780e8aa8fcc85a8540abe336ce | |
parent | b77a023de142abdd5e7d88a28fb72352708ab3d5 (diff) | |
download | markdown-9a31684b9a683fe9b0d2871649b379fadfb60ade.tar.gz markdown-9a31684b9a683fe9b0d2871649b379fadfb60ade.tar.bz2 markdown-9a31684b9a683fe9b0d2871649b379fadfb60ade.zip |
Fixed Ticket 57. Lists where the first line of an item is a nested item, now observe rules for using p tags. Thanks to Gerry LaMontagne for the patch.
-rw-r--r-- | markdown/blockprocessors.py | 19 | ||||
-rw-r--r-- | tests/misc/lists7.html | 98 | ||||
-rw-r--r-- | tests/misc/lists7.txt | 44 |
3 files changed, 159 insertions, 2 deletions
diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 98db90b..1ac2ed2 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -133,8 +133,16 @@ class ListIndentProcessor(BlockProcessor): self.parser.state.set('detabbed') if parent.tag in self.ITEM_TYPES: - # The parent is already a li. Just parse the child block. - self.parser.parseBlocks(parent, [block]) + # It's possible that this parent has a 'ul' or 'ol' child list + # with a member. If that is the case, then that should be the + # parent. This is intended to catch the edge case of an indented + # list whose first member was parsed previous to this point + # see OListProcessor + if len(parent) and parent[-1].tag in self.LIST_TYPES: + self.parser.parseBlocks(parent[-1], [block]) + else: + # The parent is already a li. Just parse the child block. + self.parser.parseBlocks(parent, [block]) elif sibling.tag in self.ITEM_TYPES: # The sibling is a li. Use it as parent. self.parser.parseBlocks(sibling, [block]) @@ -287,6 +295,13 @@ class OListProcessor(BlockProcessor): firstitem = items.pop(0) self.parser.parseBlocks(li, [firstitem]) self.parser.state.reset() + elif parent.tag in ['ol', 'ul']: + # this catches the edge case of a multi-item indented list whose + # first item is in a blank parent-list item: + # * * subitem1 + # * subitem2 + # see also ListIndentProcessor + lst = parent else: # This is a new list so create parent with appropriate tag. lst = markdown.etree.SubElement(parent, self.TAG) diff --git a/tests/misc/lists7.html b/tests/misc/lists7.html new file mode 100644 index 0000000..81c1daa --- /dev/null +++ b/tests/misc/lists7.html @@ -0,0 +1,98 @@ +<ul> +<li>item 1</li> +<li> +<ul> +<li>item 2-1</li> +<li>item 2-2</li> +<li>item 2-3</li> +<li>item 2-4</li> +</ul> +</li> +<li>item 3</li> +<li> +<ul> +<li> +<p>item 4-1</p> +</li> +<li> +<p>item 4-2</p> +</li> +<li> +<p>item 4-3</p> +</li> +<li> +<p>item 4-4</p> +</li> +</ul> +</li> +</ul> +<h2>same as above, different spacing</h2> +<ul> +<li>item 1</li> +<li> +<ul> +<li>item 2-1</li> +<li>item 2-2</li> +</ul> +</li> +<li>item 3</li> +<li> +<ul> +<li> +<p>item 4-1</p> +</li> +<li> +<p>item 4-2</p> +</li> +</ul> +</li> +</ul> +<h2>only 1 item in nested list ##</h2> +<ul> +<li>item 1</li> +<li> +<ul> +<li>item 2-1</li> +</ul> +</li> +<li>item 3</li> +<li> +<ul> +<li>item 4-1</li> +</ul> +</li> +</ul> +<h2>Something ludicrous ##</h2> +<ul> +<li>item 1</li> +<li> +<ul> +<li>item 2-1</li> +<li>item 2-2</li> +<li> +<ul> +<li>item 2-2-1</li> +<li>item 2-2-2</li> +</ul> +</li> +<li>item 2-3</li> +</ul> +</li> +<li>item 3</li> +<li> +<ul> +<li> +<p>item 4-1</p> +</li> +<li> +<ul> +<li>item 4-1-1</li> +<li>item 4-1-2</li> +</ul> +</li> +<li> +<p>item 4-2</p> +</li> +</ul> +</li> +</ul>
\ No newline at end of file diff --git a/tests/misc/lists7.txt b/tests/misc/lists7.txt new file mode 100644 index 0000000..77181c8 --- /dev/null +++ b/tests/misc/lists7.txt @@ -0,0 +1,44 @@ +* item 1 +* * item 2-1 + * item 2-2 + * item 2-3 + * item 2-4 +* item 3 +* * item 4-1 + + * item 4-2 + + * item 4-3 + + * item 4-4 + +## same as above, different spacing +* item 1 +* * item 2-1 + * item 2-2 +* item 3 +* * item 4-1 + + * item 4-2 + +## only 1 item in nested list ## +* item 1 +* * item 2-1 +* item 3 +* * item 4-1 + +## Something ludicrous ## +* item 1 +* * item 2-1 + * item 2-2 + * * item 2-2-1 + * item 2-2-2 + * item 2-3 +* item 3 +* * item 4-1 + + * * item 4-1-1 + * item 4-1-2 + + * item 4-2 + |