diff --git a/markdownify/__init__.py b/markdownify/__init__.py index dd2507d..5cbf95f 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -244,8 +244,8 @@ def escape(self, text): text = text.replace('_', r'\_') return text - def indent(self, text, level): - return line_beginning_re.sub('\t' * level, text) if text else '' + def indent(self, text, columns): + return line_beginning_re.sub(' ' * columns, text) if text else '' def underline(self, text, pad_char): text = (text or '').rstrip() @@ -346,7 +346,7 @@ def convert_list(self, el, text, convert_as_inline): el = el.parent if nested: # remove trailing newline if nested - return '\n' + self.indent(text, 1).rstrip() + return '\n' + text.rstrip() return '\n\n' + text + ('\n' if before_paragraph else '') convert_ul = convert_list @@ -368,7 +368,12 @@ def convert_li(self, el, text, convert_as_inline): el = el.parent bullets = self.options['bullets'] bullet = bullets[depth % len(bullets)] - return '%s %s\n' % (bullet, (text or '').strip()) + bullet = bullet + ' ' + text = (text or '').strip() + text = self.indent(text, len(bullet)) + if text: + text = bullet + text[len(bullet):] + return '%s\n' % text def convert_p(self, el, text, convert_as_inline): if convert_as_inline: diff --git a/tests/test_lists.py b/tests/test_lists.py index ecc1a65..a660778 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -47,10 +47,11 @@ def test_ol(): assert md('
first para
second para
third para
fourth para
first para
second para
third para
fourth para