From 461dbb80de64cdfc0c29c3625f0c70b9653b7370 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Sat, 22 Nov 2008 15:07:35 -0500 Subject: Made a few minor tweaks to list blockprocessors to make subclassing easier without rewriting the whole thing. --- markdown/blockprocessors.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 646ae9f..2ae4d08 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -113,12 +113,15 @@ class ListIndentProcessor(BlockProcessor): """ + ITEM_TYPES = ['li'] + LIST_TYPES = ['ul', 'ol'] + def test(self, parent, block): return block.startswith(' '*markdown.TAB_LENGTH) and \ not self.parser.state.isstate('detabbed') and \ - (parent.tag == "li" or \ + (parent.tag in self.ITEM_TYPES or \ (len(parent) and parent[-1] and \ - (parent[-1].tag == "ul" or parent[-1].tag == "ol") + (parent[-1].tag in self.LIST_TYPES) ) ) @@ -126,10 +129,10 @@ class ListIndentProcessor(BlockProcessor): block = self.looseDetab(blocks.pop(0)) sibling = self.lastChild(parent) self.parser.state.set('detabbed') - if parent.tag == 'li': + if parent.tag in self.ITEM_TYPES: # The parent is already a li. Just parse the child block. self.parser.parseBlocks(parent, [block]) - elif len(sibling) and sibling[-1].tag == 'li': + elif len(sibling) and sibling[-1].tag in self.ITEM_TYPES : # The parent is a list (``ol`` or ``ul``) which has children. # Assume the last child li is the parent of this block. if sibling[-1].text: @@ -138,11 +141,15 @@ class ListIndentProcessor(BlockProcessor): sibling[-1].text = '' self.parser.parseChunk(sibling[-1], block) else: - # Create a new li and parse the block with it as the parent. - li = markdown.etree.SubElement(sibling, 'li') - self.parser.parseBlocks(li, [block]) + create_item(sibling, block) self.parser.state.reset() + def create_item(parent, block): + """ Create a new li and parse the block with it as the parent. """ + li = markdown.etree.SubElement(sibling, 'li') + self.parser.parseBlocks(li, [block]) + + class CodeBlockProcessor(BlockProcessor): """ Process code blocks. """ @@ -230,7 +237,7 @@ class OListProcessor(BlockProcessor): # Check fr multiple items in one block. items = self.get_items(blocks.pop(0)) sibling = self.lastChild(parent) - if sibling and (sibling.tag == 'ol' or sibling.tag == 'ul'): + if sibling and sibling.tag in ['ol', 'ul']: # Previous block was a list item, so set that as parent lst = sibling # make sure previous item is in a p. -- cgit v1.2.3