diff options
author | Waylan Limberg <waylan@gmail.com> | 2011-06-15 08:50:55 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2011-06-15 08:50:55 -0400 |
commit | 8a64c2970ca99f1586bc85a59898bfe7269c9128 (patch) | |
tree | cd28870f08030ce4827117fec69e9706c52f2528 | |
parent | 11124d9f8ddd547c93078dcf6380deacec7fc32f (diff) | |
download | markdown-8a64c2970ca99f1586bc85a59898bfe7269c9128.tar.gz markdown-8a64c2970ca99f1586bc85a59898bfe7269c9128.tar.bz2 markdown-8a64c2970ca99f1586bc85a59898bfe7269c9128.zip |
Fixed #21. A header and paragraph not seperated by a blank line inside a list item are now parsed correctly. One of those crazy wierd edge cases that no one would ever test for, but is obvious once you see it.
-rw-r--r-- | markdown/blockprocessors.py | 31 | ||||
-rw-r--r-- | tests/misc/header-in-lists.html | 20 | ||||
-rw-r--r-- | tests/misc/header-in-lists.txt | 14 |
3 files changed, 61 insertions, 4 deletions
diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 6396b4a..2695932 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -328,6 +328,13 @@ class OListProcessor(BlockProcessor): p.text = lst[-1].text lst[-1].text = '' lst[-1].insert(0, p) + # if the last item has a tail, then the tail needs to be put in a p + # likely only when a header is not followed by a blank line + lch = self.lastChild(lst[-1]) + if lch is not None and lch.tail: + p = util.etree.SubElement(lst[-1], 'p') + p.text = lch.tail.lstrip() + lch.tail = '' # parse first block differently as it gets wrapped in a p. li = util.etree.SubElement(lst, 'li') @@ -518,11 +525,27 @@ class ParagraphProcessor(BlockProcessor): if block.strip(): # Not a blank block. Add to parent, otherwise throw it away. if self.parser.state.isstate('list'): - # The parent is a tight-list. Append to parent.text - if parent.text: - parent.text = '%s\n%s' % (parent.text, block) + # The parent is a tight-list. + # + # Check for any children. This will likely only happen in a + # tight-list when a header isn't followed by a blank line. + # For example: + # + # * # Header + # Line 2 of list item - not part of header. + sibling = self.lastChild(parent) + if sibling is not None: + # Insetrt after sibling. + if sibling.tail: + sibling.tail = '%s\n%s' % (sibling.tail, block) + else: + sibling.tail = '\n%s' % block else: - parent.text = block.lstrip() + # Append to parent.text + if parent.text: + parent.text = '%s\n%s' % (parent.text, block) + else: + parent.text = block.lstrip() else: # Create a regular paragraph p = util.etree.SubElement(parent, 'p') diff --git a/tests/misc/header-in-lists.html b/tests/misc/header-in-lists.html new file mode 100644 index 0000000..61a6d97 --- /dev/null +++ b/tests/misc/header-in-lists.html @@ -0,0 +1,20 @@ +<p>Tight List:</p> +<ul> +<li> +<h1>Header1</h1> +Line 1-2 - not a header or paragraph!</li> +<li> +<h1>Header2</h1> +Line 2-2 - not a header or paragraph!</li> +</ul> +<p>Loose List:</p> +<ul> +<li> +<h1>Header1</h1> +<p>Line 1-2 - a paragraph</p> +</li> +<li> +<h1>Header2</h1> +<p>Line 2-2 - a paragraph</p> +</li> +</ul>
\ No newline at end of file diff --git a/tests/misc/header-in-lists.txt b/tests/misc/header-in-lists.txt new file mode 100644 index 0000000..b633d8a --- /dev/null +++ b/tests/misc/header-in-lists.txt @@ -0,0 +1,14 @@ +Tight List: + +* #Header1 +Line 1-2 - not a header or paragraph! +* #Header2 +Line 2-2 - not a header or paragraph! + +Loose List: + +* #Header1 +Line 1-2 - a paragraph + +* #Header2 +Line 2-2 - a paragraph |