diff --git a/markdownify/__init__.py b/markdownify/__init__.py index f97bcbf..b7c9545 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -151,14 +151,19 @@ class MarkdownConverter(object): def convert_list(self, el, text): nested = False + before_paragraph = False + print(el.name, repr(el.next_sibling), repr(text)) + if el.next_sibling and el.next_sibling.name not in ['ul', 'ol']: + print(el.name, repr(el.next_sibling)) + before_paragraph = True while el: if el.name == 'li': nested = True break el = el.parent if nested: - text = '\n' + self.indent(text, 1) - return '\n' + text + '\n' + text = '\n' + self.indent(text, 1).rstrip() + return text + ('\n' if before_paragraph else '') convert_ul = convert_list convert_ol = convert_list diff --git a/tests/test_conversions.py b/tests/test_conversions.py index dfc8d3c..98065bb 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -2,7 +2,7 @@ from markdownify import markdownify as md, ATX, ATX_CLOSED import re -nested_uls = re.sub('\s+', '', """ +nested_uls = """
hello
') == 'hello\n\n' @@ -113,11 +134,11 @@ def test_nested_uls(): Nested ULs should alternate bullet characters. """ - assert md(nested_uls) == '* 1\n\t+ a\n\t\t- I\n\t\t- II\n\t\t- III\n\t\t\n\t+ b\n\t+ c\n\t\n* 2\n* 3\n' + assert md(nested_uls) == '* 1 \n\t+ a \n\t\t- I\n\t\t- II\n\t\t- III\n\t+ b\n\t+ c\n* 2\n* 3\n' def test_bullets(): - assert md(nested_uls, bullets='-') == '- 1\n\t- a\n\t\t- I\n\t\t- II\n\t\t- III\n\t\t\n\t- b\n\t- c\n\t\n- 2\n- 3\n' + assert md(nested_uls, bullets='-') == '- 1 \n\t- a \n\t\t- I\n\t\t- II\n\t\t- III\n\t- b\n\t- c\n- 2\n- 3\n' def test_img():