From 8d367ca71c610c49d3b3d5c81f49cb38f9e97fb9 Mon Sep 17 00:00:00 2001
From: Waylan Limberg
Date: Wed, 12 Nov 2008 23:00:31 -0500
Subject: Fixed various issues with the core parser - mostly whitespace related
and updated a few tests that weren't quite right - that is they now better
match pl or php implementations.
---
markdown.py | 112 ++++++++++++++++++++--------
tests/misc/blockquote.html | 6 +-
tests/misc/multi-paragraph-block-quote.html | 4 +-
3 files changed, 86 insertions(+), 36 deletions(-)
diff --git a/markdown.py b/markdown.py
index b40093f..9fc6355 100755
--- a/markdown.py
+++ b/markdown.py
@@ -240,17 +240,26 @@ class ListIndentProcessor(BlockProcessor):
""" Process children of list items. """
def test(self, parent, block):
- return block.startswith(' '*4) and parent[-1] and \
- (parent[-1].tag == "ul" or parent[-1].tag == "ol")
+ return block.startswith(' '*4) and \
+ (parent.tag == "li" or \
+ (len(parent) and parent[-1] and \
+ (parent[-1].tag == "ul" or parent[-1].tag == "ol")
+ )
+ )
def run(self, parent, blocks):
- block = blocks.pop(0)
+ block = self.looseDetab(blocks.pop(0))
sibling = self.lastChild(parent)
- if len(sibling) and sibling[-1].tag == 'li':
- self.parser.parseBlocks(sibling[-1], [self.looseDetab(block)])
+ if parent.tag == 'li':
+ self.parser.parseBlocks(parent, [block])
+ elif len(sibling) and sibling[-1].tag == 'li':
+ if sibling[-1].text:
+ block = '%s\n\n%s' % (sibling[-1].text, block)
+ sibling[-1].text = ''
+ self.parser.parseChunk(sibling[-1], block)
else:
li = etree.SubElement(sibling, 'li')
- self.parser.parseBlocks(li, [self.looseDetab(block)])
+ self.parser.parseBlocks(li, [block])
class CodeBlockProcessor(BlockProcessor):
@@ -267,12 +276,12 @@ class CodeBlockProcessor(BlockProcessor):
and sibling[0].tag == "code":
code = sibling[0]
block, theRest = self.detab(block)
- code.text = '%s\n%s\n' % (code.text, block.rstrip())
+ code.text = AtomicString('%s\n%s\n' % (code.text, block.rstrip()))
else:
pre = etree.SubElement(parent, 'pre')
code = etree.SubElement(pre, 'code')
block, theRest = self.detab(block)
- code.text = '%s\n' % block.rstrip()
+ code.text = AtomicString('%s\n' % block.rstrip())
if theRest:
blocks.insert(0, theRest)
@@ -292,15 +301,15 @@ class BlockQuoteProcessor(BlockProcessor):
quote = sibling
else:
quote = etree.SubElement(parent, 'blockquote')
- self.parser.parseBlocks(quote, [block])
+ self.parser.parseChunk(quote, block)
def clean(self, line):
""" Remove ``>`` from begining of a line. """
m = self.RE.match(line)
- if m:
- return m.group(1)
- elif line.strip() == ">":
+ if line.strip() == ">":
return ""
+ elif m:
+ return m.group(1)
else:
return line
@@ -318,7 +327,7 @@ class OListProcessor(BlockProcessor):
sibling = self.lastChild(parent)
if sibling and sibling.tag == self.TAG:
lst = sibling
- # make sure previous item is in a p.
+ # make sure previous item is in a p.
if len(lst) and lst[-1].text and not len(lst[-1]):
p = etree.SubElement(lst[-1], 'p')
p.text = lst[-1].text
@@ -333,8 +342,11 @@ class OListProcessor(BlockProcessor):
lst = etree.SubElement(parent, self.TAG)
self.parser.state = 'list'
for item in items:
- li = etree.SubElement(lst, 'li')
- self.parser.parseBlocks(li, [item])
+ if item.startswith(' '*4):
+ self.parser.parseBlocks(lst[-1], [item])
+ else:
+ li = etree.SubElement(lst, 'li')
+ self.parser.parseBlocks(li, [item])
self.parser.resetState()
def get_items(self, block):
@@ -344,6 +356,11 @@ class OListProcessor(BlockProcessor):
m = self.RE.match(line)
if m:
items.append(m.group(1))
+ elif line.startswith(' '*4):
+ if items[-1].startswith(' '*4):
+ items[-1] = '%s\n%s' % (items[-1], line)
+ else:
+ items.append(line)
else:
items[-1] = '\n'.join([items[-1], line])
return items
@@ -359,22 +376,25 @@ class UListProcessor(OListProcessor):
class HashHeaderProcessor(BlockProcessor):
""" Process Hash Headers. """
- RE = re.compile(r'^(#{1,6})(.*?)#*$')
+ RE = re.compile(r'(^|\n)(?P#{1,6})(?P
This is line one of paragraph two
-
-
This is another blockquote.
\ No newline at end of file
--
cgit v1.2.3