diff options
-rw-r--r-- | markdown/__init__.py | 2 | ||||
-rw-r--r-- | markdown/blockprocessors.py | 13 |
2 files changed, 8 insertions, 7 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py index 959f387..fbd2879 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -283,8 +283,8 @@ class Markdown: source = source.replace(util.STX, "").replace(util.ETX, "") source = source.replace("\r\n", "\n").replace("\r", "\n") + "\n\n" - source = re.sub(r'\n\s+\n', '\n\n', source) source = source.expandtabs(self.tab_length) + source = re.sub(r'\n +\n', '\n\n', source) # Split into lines and run the line preprocessors. self.lines = source.split("\n") 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): |