From b747378b52163c7e0e369c74abb0a486ddfb1e81 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sun, 9 Aug 2020 21:11:16 +0200 Subject: [PATCH] fixed nested lists and wrote correct tests nested lists did not work: after a nested list was over, a new line was inserted. this leads to a large gap before the rest of the parent list. lists are prefixed and suffixed with a single newline, this is now represented in the tests. --- markdownify/__init__.py | 3 ++- tests/test_conversions.py | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index d126cae..4a44737 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -169,7 +169,8 @@ class MarkdownConverter(object): break el = el.parent if nested: - text = '\n' + self.indent(text, 1) + # remove trailing newline if nested + return '\n' + self.indent(text, 1).rstrip() return '\n' + text + '\n' convert_ul = convert_list diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 2526af3..853ed66 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 = re.sub(r'\s+', '', """