Skip to content

Commit 600f77d

Browse files
authored
allow a wrap_width value of None for unlimited line lengths (#169)
allow a wrap_width value of None to reflow text to unlimited line length
1 parent 9339571 commit 600f77d

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

Diff for: README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ wrap, wrap_width
143143
If ``wrap`` is set to ``True``, all text paragraphs are wrapped at
144144
``wrap_width`` characters. Defaults to ``False`` and ``80``.
145145
Use with ``newline_style=BACKSLASH`` to keep line breaks in paragraphs.
146+
A `wrap_width` value of `None` reflows lines to unlimited line length.
146147

147148
Options may be specified as kwargs to the ``markdownify`` function, or as a
148149
nested ``Options`` class in ``MarkdownConverter`` subclasses.

Diff for: markdownify/__init__.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -400,18 +400,19 @@ def convert_p(self, el, text, convert_as_inline):
400400
# Preserve newlines (and preceding whitespace) resulting
401401
# from <br> tags. Newlines in the input have already been
402402
# replaced by spaces.
403-
lines = text.split('\n')
404-
new_lines = []
405-
for line in lines:
406-
line = line.lstrip()
407-
line_no_trailing = line.rstrip()
408-
trailing = line[len(line_no_trailing):]
409-
line = fill(line,
410-
width=self.options['wrap_width'],
411-
break_long_words=False,
412-
break_on_hyphens=False)
413-
new_lines.append(line + trailing)
414-
text = '\n'.join(new_lines)
403+
if self.options['wrap_width'] is not None:
404+
lines = text.split('\n')
405+
new_lines = []
406+
for line in lines:
407+
line = line.lstrip()
408+
line_no_trailing = line.rstrip()
409+
trailing = line[len(line_no_trailing):]
410+
line = fill(line,
411+
width=self.options['wrap_width'],
412+
break_long_words=False,
413+
break_on_hyphens=False)
414+
new_lines.append(line + trailing)
415+
text = '\n'.join(new_lines)
415416
return '\n\n%s\n\n' % text if text else ''
416417

417418
def convert_pre(self, el, text, convert_as_inline):

Diff for: tests/test_conversions.py

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def test_p():
224224
assert md('<p>123456789 123456789</p>') == '\n\n123456789 123456789\n\n'
225225
assert md('<p>123456789\n\n\n123456789</p>') == '\n\n123456789\n123456789\n\n'
226226
assert md('<p>123456789\n\n\n123456789</p>', wrap=True, wrap_width=80) == '\n\n123456789 123456789\n\n'
227+
assert md('<p>123456789\n\n\n123456789</p>', wrap=True, wrap_width=None) == '\n\n123456789 123456789\n\n'
227228
assert md('<p>123456789 123456789</p>', wrap=True, wrap_width=10) == '\n\n123456789\n123456789\n\n'
228229
assert md('<p><a href="https://example.com">Some long link</a></p>', wrap=True, wrap_width=10) == '\n\n[Some long\nlink](https://example.com)\n\n'
229230
assert md('<p>12345<br />67890</p>', wrap=True, wrap_width=10, newline_style=BACKSLASH) == '\n\n12345\\\n67890\n\n'

0 commit comments

Comments
 (0)