Skip to content

Commit db39bab

Browse files
committed
fix text newline
1 parent c208d24 commit db39bab

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pyoa_graphics.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,21 @@ def wrap_nicely(string, max_chars):
239239
:param int max_chars: The maximum number of characters on a line before wrapping.
240240
241241
"""
242-
string = string.replace('\n', '').replace('\r', '') # strip confusing newlines
242+
#string = string.replace('\n', '').replace('\r', '') # strip confusing newlines
243243
words = string.split(' ')
244244
the_lines = []
245245
the_line = ""
246246
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:
250253
the_lines.append(the_line)
251254
the_line = ''+w
255+
else:
256+
the_line += ' '+w
252257
if the_line: # last line remaining
253258
the_lines.append(the_line)
254259
# remove first space from first line:

0 commit comments

Comments
 (0)