File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -239,16 +239,21 @@ def wrap_nicely(string, max_chars):
239
239
:param int max_chars: The maximum number of characters on a line before wrapping.
240
240
241
241
"""
242
- string = string .replace ('\n ' , '' ).replace ('\r ' , '' ) # strip confusing newlines
242
+ # string = string.replace('\n', '').replace('\r', '') # strip confusing newlines
243
243
words = string .split (' ' )
244
244
the_lines = []
245
245
the_line = ""
246
246
for w in words :
247
- if len (the_line + ' ' + w ) <= max_chars :
248
- the_line += ' ' + w
249
- else :
247
+ if '\n ' in w :
248
+ w1 , w2 = w .split ('\n ' )
249
+ the_line += ' ' + w1
250
+ the_lines .append (the_line )
251
+ the_line = w2
252
+ elif len (the_line + ' ' + w ) > max_chars :
250
253
the_lines .append (the_line )
251
254
the_line = '' + w
255
+ else :
256
+ the_line += ' ' + w
252
257
if the_line : # last line remaining
253
258
the_lines .append (the_line )
254
259
# remove first space from first line:
You can’t perform that action at this time.
0 commit comments