Skip to content

Commit

Permalink
Blockquoted text in the first item of a list is now placed in child p…
Browse files Browse the repository at this point in the history
… tag of the

blockquote tag.  Added lists8.txt and .html for test suite to test condition.
  • Loading branch information
lama7 committed Mar 23, 2010
1 parent ced8f58 commit 3c5a355
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 25 deletions.
28 changes: 3 additions & 25 deletions markdown/blockprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,10 @@ def test(self, parent, block):
)

def run(self, parent, blocks):
print "BEGIN ListIndentProcessor"
print "parent: %s" % markdown.etree.tostring(parent)
print "blocks: %s" % blocks

block = blocks.pop(0)
level, sibling = self.get_level(parent, block)
block = self.looseDetab(block, level)

print "block: %s" % block
if sibling:
print "sibling: %s" % markdown.etree.tostring(sibling)
else:
print "sibling: none"

self.parser.state.set('detabbed')
if parent.tag in self.ITEM_TYPES:
# It's possible that this parent has a 'ul' or 'ol' child list
Expand Down Expand Up @@ -172,8 +162,6 @@ def run(self, parent, blocks):
self.create_item(sibling, block)
self.parser.state.reset()

print "END ListIndentProcessor"

def create_item(self, parent, block):
""" Create a new li and parse the block with it as the parent. """
li = markdown.etree.SubElement(parent, 'li')
Expand Down Expand Up @@ -263,7 +251,10 @@ def run(self, parent, blocks):
# This is a new blockquote. Create a new parent element.
quote = markdown.etree.SubElement(parent, 'blockquote')
# Recursively parse block with blockquote as parent.
# change parser state so blockquotes embedded in lists use p tags
self.parser.state.set('blockquote')
self.parser.parseChunk(quote, block)
self.parser.state.reset()

def clean(self, line):
""" Remove ``>`` from beginning of a line. """
Expand All @@ -290,20 +281,10 @@ def test(self, parent, block):
return bool(self.RE.match(block))

def run(self, parent, blocks):
print "BEGIN OListProcessor"
print "parent: %s" % markdown.etree.tostring(parent)
print "blocks: %s" % blocks

# Check fr multiple items in one block.
items = self.get_items(blocks.pop(0))
sibling = self.lastChild(parent)

print "items: %s" % items
if sibling:
print "sibling: %s" % markdown.etree.tostring(sibling)
else:
print "sibling: none"

if sibling and sibling.tag in ['ol', 'ul']:
# Previous block was a list item, so set that as parent
lst = sibling
Expand All @@ -323,7 +304,6 @@ def run(self, parent, blocks):
self.parser.state.set('looselist')
firstitem = items.pop(0)
self.parser.parseBlocks(li, [firstitem])
print "looselist: %s" % markdown.etree.tostring(lst)
self.parser.state.reset()
elif parent.tag in ['ol', 'ul']:
# this catches the edge case of a multi-item indented list whose
Expand All @@ -348,8 +328,6 @@ def run(self, parent, blocks):
self.parser.parseBlocks(li, [item])
self.parser.state.reset()

print "END OListProcessor"

def get_items(self, block):
""" Break a block into list items. """
items = []
Expand Down
39 changes: 39 additions & 0 deletions tests/misc/lists8.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<h1>Lists with blockquotes</h1>
<ol>
<li>
<blockquote>
<p>Four-score and seven years ago...</p>
</blockquote>
</li>
<li>
<blockquote>
<p>We have nothing to fear...</p>
</blockquote>
</li>
<li>
<blockquote>
<p>This is it...</p>
</blockquote>
</li>
</ol>
<h1>Multi-line blockquotes</h1>
<ul>
<li>
<blockquote>
<p>Four-score and sever years ago
our fathers brought forth</p>
</blockquote>
</li>
<li>
<blockquote>
<p>We have nothing to fear
but fear itself</p>
</blockquote>
</li>
<li>
<blockquote>
<p>This is it
as far as I'm concerned</p>
</blockquote>
</li>
</ul>
16 changes: 16 additions & 0 deletions tests/misc/lists8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Lists with blockquotes
1. > Four-score and seven years ago...

2. > We have nothing to fear...

3. > This is it...

# Multi-line blockquotes
* > Four-score and sever years ago
> our fathers brought forth

* > We have nothing to fear
> but fear itself

* > This is it
> as far as I'm concerned

0 comments on commit 3c5a355

Please sign in to comment.