else:
# Content
# collapse whitespace and wrap.
- ret += textwrap.fill(re.sub(r'\s+', ' ', m), width,
- initial_indent=indent+bindent,
- subsequent_indent=indent+bindent,
- break_long_words=False,
- break_on_hyphens=False).lstrip()
- ret += '\n'
+ if '\n\n' in m:
+ # list appears to end and have further content.
+ # deal with final (?) bullet...
+ bm, rest = m.split('\n\n', 1)
+ ret += textwrap.fill(re.sub(r'\s+', ' ', bm), width,
+ initial_indent=indent+bindent,
+ subsequent_indent=indent+bindent,
+ break_long_words=False,
+ break_on_hyphens=False).lstrip()
+
+ # ... and then indent and wrap following content normally.
+ ret += '\n\n'
+ ret += textwrap.fill(re.sub(r'\s+', ' ', rest), width,
+ initial_indent=indent,
+ subsequent_indent=indent,
+ break_long_words=False,
+ break_on_hyphens=False)
+ ret += '\n'
+ else:
+ ret += textwrap.fill(re.sub(r'\s+', ' ', m), width,
+ initial_indent=indent+bindent,
+ subsequent_indent=indent+bindent,
+ break_long_words=False,
+ break_on_hyphens=False).lstrip()
+ ret += '\n'
return ret.rstrip()
except Exception as e: