diff --git a/CHANGELOG.textile b/CHANGELOG.textile index a3ff742..a6a67da 100644 --- a/CHANGELOG.textile +++ b/CHANGELOG.textile @@ -1,5 +1,10 @@ + h1. Textile Changelog +h2. Development +* Bugfixes: +** Allow text blocks with spaces around first and last newlines + h2. Version 4.0.3 * Update supported Python versions to 3.8 - 3.12 ("#83":https://github.com/textile/python-textile/issues/83) * Replace html5lib with nh3 for html sanitization diff --git a/tests/test_textile.py b/tests/test_textile.py index 84e9ddf..1916ec4 100644 --- a/tests/test_textile.py +++ b/tests/test_textile.py @@ -242,3 +242,9 @@ def test_relURL(): t = textile.Textile() t.restricted = True assert t.relURL("gopher://gopher.com/") == '#' + + +def test_whitespace_at_beginning_and_end(): + expect = textile.textile(' \n Testing 1 2 3 \n ', html_type='html5') + result = '\t
Testing 1 2 3
' + assert result == expect diff --git a/textile/core.py b/textile/core.py index 4a2594f..fe9e2ea 100644 --- a/textile/core.py +++ b/textile/core.py @@ -442,9 +442,8 @@ def block(self, text): tag = 'p' atts = cite = ext = '' - out = [] - + block = None for line in text: # the line is just whitespace, add it to the output, and move on if not line.strip(): diff --git a/textile/utils.py b/textile/utils.py index 578af4e..2f2afd8 100644 --- a/textile/utils.py +++ b/textile/utils.py @@ -149,7 +149,9 @@ def list_type(list_string): def normalize_newlines(string): out = re.sub(r'\r\n?', '\n', string) - out = re.compile(r'^[ \t]*\n', flags=re.M).sub('\n', out) + # strip spaces around first and last newline + out = re.compile(r'^[ \t]*\n[ \t]*', flags=re.M).sub('\n', out) + out = re.compile(r'[ \t]*\n[ \t]*$', flags=re.M).sub('\n', out) out = out.strip('\n') return out