Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/test_textile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<p>Testing 1 2 3</p>'
assert result == expect
3 changes: 1 addition & 2 deletions textile/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 3 additions & 1 deletion textile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down