diff options
-rw-r--r-- | markdown/__init__.py | 1 | ||||
-rw-r--r-- | markdown/blockprocessors.py | 2 | ||||
-rw-r--r-- | markdown/treeprocessors.py | 5 |
3 files changed, 7 insertions, 1 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py index be45a8b..fbd2879 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -284,6 +284,7 @@ class Markdown: source = source.replace(util.STX, "").replace(util.ETX, "") source = source.replace("\r\n", "\n").replace("\r", "\n") + "\n\n" 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 3c320f8..b41df6a 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'(^ *$)|(^ *\n)') + RE = re.compile(r'^ *(\n|$)') def test(self, parent, block): return bool(self.RE.match(block)) diff --git a/markdown/treeprocessors.py b/markdown/treeprocessors.py index fb107d2..b5eedbd 100644 --- a/markdown/treeprocessors.py +++ b/markdown/treeprocessors.py @@ -357,3 +357,8 @@ class PrettifyTreeprocessor(Treeprocessor): br.tail = '\n' else: br.tail = '\n%s' % br.tail + # Clean up extra empty lines at end of code blocks. + pres = root.getiterator('pre') + for pre in pres: + if len(pre) and pre[0].tag == 'code': + pre[0].text = pre[0].text.rstrip() + '\n' |