aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/blockprocessors.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2013-02-06 16:05:52 -0500
committerWaylan Limberg <waylan@gmail.com>2013-02-06 16:05:52 -0500
commitd5a94c21313915ebbd50c061bf19e68ef6dee115 (patch)
tree0bf1cd8c1c68b42458a225418efc157132d021a2 /markdown/blockprocessors.py
parent4ff74e33a48a8c4e101d2f5e259d7b911c03d9f9 (diff)
downloadmarkdown-d5a94c21313915ebbd50c061bf19e68ef6dee115.tar.gz
markdown-d5a94c21313915ebbd50c061bf19e68ef6dee115.tar.bz2
markdown-d5a94c21313915ebbd50c061bf19e68ef6dee115.zip
Preserve empty lines in code blocks
Partial fix for #183. Some lines are still being lost. When the processors are run, one line is lost. When their calling code is comments out (completely skiped) a line is still lost if more than 3 exist in a row. Also need to add some tests for this.
Diffstat (limited to 'markdown/blockprocessors.py')
-rw-r--r--markdown/blockprocessors.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py
index 1e6160f..3c320f8 100644
--- a/markdown/blockprocessors.py
+++ b/markdown/blockprocessors.py
@@ -499,7 +499,7 @@ class EmptyBlockProcessor(BlockProcessor):
# Detect a block that only contains whitespace
# or only whitespace on the first line.
- RE = re.compile(r'^\s*\n')
+ RE = re.compile(r'(^ *$)|(^ *\n)')
def test(self, parent, block):
return bool(self.RE.match(block))
@@ -508,13 +508,14 @@ class EmptyBlockProcessor(BlockProcessor):
block = blocks.pop(0)
m = self.RE.match(block)
if m:
- # Add remaining line to master blocks for later.
- blocks.insert(0, block[m.end():])
+ theRest = block[m.end():]
+ if theRest:
+ # Add remaining lines to master blocks for later.
+ blocks.insert(0, theRest)
sibling = self.lastChild(parent)
- if sibling and sibling.tag == 'pre' and sibling[0] and \
- sibling[0].tag == 'code':
+ if sibling and sibling.tag == 'pre' and len(sibling) and sibling[0].tag == 'code':
# Last block is a codeblock. Append to preserve whitespace.
- sibling[0].text = util.AtomicString('%s/n/n/n' % sibling[0].text )
+ sibling[0].text = util.AtomicString('%s\n' % sibling[0].text )
class ParagraphProcessor(BlockProcessor):