Merge pull request #14 from snahor/preserve-newlines
Preserve newlines in comments and posts
This commit is contained in:
@@ -7,6 +7,7 @@ import six
|
|||||||
|
|
||||||
from .errors import SubmissionURLError, SubredditNameError
|
from .errors import SubmissionURLError, SubredditNameError
|
||||||
|
|
||||||
|
|
||||||
def clean(unicode_string):
|
def clean(unicode_string):
|
||||||
"""
|
"""
|
||||||
Convert unicode string into ascii-safe characters.
|
Convert unicode string into ascii-safe characters.
|
||||||
@@ -21,6 +22,17 @@ def clean(unicode_string):
|
|||||||
return ascii_string
|
return ascii_string
|
||||||
|
|
||||||
|
|
||||||
|
def split_text(big_text, width):
|
||||||
|
return [
|
||||||
|
text
|
||||||
|
for line in big_text.splitlines()
|
||||||
|
# wrap returns an empty list when "line" is a newline
|
||||||
|
# in order to consider newlines we need a list containing an
|
||||||
|
# empty string
|
||||||
|
for text in (textwrap.wrap(line, width=width) or [''])
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def strip_subreddit_url(permalink):
|
def strip_subreddit_url(permalink):
|
||||||
"""
|
"""
|
||||||
Grab the subreddit from the permalink because submission.subreddit.url
|
Grab the subreddit from the permalink because submission.subreddit.url
|
||||||
@@ -219,7 +231,7 @@ class SubmissionContent(BaseContent):
|
|||||||
elif index == -1:
|
elif index == -1:
|
||||||
data = self._submission_data
|
data = self._submission_data
|
||||||
data['split_title'] = textwrap.wrap(data['title'], width=n_cols-2)
|
data['split_title'] = textwrap.wrap(data['title'], width=n_cols-2)
|
||||||
data['split_text'] = textwrap.wrap(data['text'], width=n_cols-2)
|
data['split_text'] = split_text(data['text'], width=n_cols-2)
|
||||||
data['n_rows'] = (len(data['split_title']) + len(data['split_text']) + 5)
|
data['n_rows'] = (len(data['split_title']) + len(data['split_text']) + 5)
|
||||||
data['offset'] = 0
|
data['offset'] = 0
|
||||||
|
|
||||||
@@ -229,7 +241,7 @@ class SubmissionContent(BaseContent):
|
|||||||
data['offset'] = indent_level * self.indent_size
|
data['offset'] = indent_level * self.indent_size
|
||||||
|
|
||||||
if data['type'] == 'Comment':
|
if data['type'] == 'Comment':
|
||||||
data['split_body'] = textwrap.wrap(
|
data['split_body'] = split_text(
|
||||||
data['body'], width=n_cols-data['offset'])
|
data['body'], width=n_cols-data['offset'])
|
||||||
data['n_rows'] = len(data['split_body']) + 1
|
data['n_rows'] = len(data['split_body']) + 1
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user