diff options
author | Waylan Limberg <waylan@gmail.com> | 2013-02-08 06:50:25 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2013-02-08 06:50:25 -0500 |
commit | a0df080088bef0fac603b83752a36c5c403016e6 (patch) | |
tree | 04ad4b2fb13032c677e472515fad8f34dffe50e4 | |
parent | 25e187598f06f04feeacbf967b7651e93286d3f4 (diff) | |
download | markdown-a0df080088bef0fac603b83752a36c5c403016e6.tar.gz markdown-a0df080088bef0fac603b83752a36c5c403016e6.tar.bz2 markdown-a0df080088bef0fac603b83752a36c5c403016e6.zip |
Cleaned up fixes for #183
My previous commit (d5a94c2) broke a few things badly. Unfortunately I failed
to run the complete test suite and didn't catch it. A bad regex was crashing
the test suite. Also cleaned up a few other odds and ends from previous work
on #183. Still loosing a few random empty lines in code blocks though.
I suspect this may also fix #188.
-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' |