From 33a6bc786d7641fe23ffcc667f4e0f292c7f4088 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 6 Aug 2022 14:23:03 +0100 Subject: [PATCH 1/3] Fix incorrect test case for `break-on-newline` extra --- .../break_on_newline_excessive_br_tags_in_ul.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/tm-cases/break_on_newline_excessive_br_tags_in_ul.html b/test/tm-cases/break_on_newline_excessive_br_tags_in_ul.html index 23a3e646..19075c61 100644 --- a/test/tm-cases/break_on_newline_excessive_br_tags_in_ul.html +++ b/test/tm-cases/break_on_newline_excessive_br_tags_in_ul.html @@ -3,10 +3,12 @@

Conteúdo

Ordered List

From a4158cc5074716d027ddbb5f624b499b75b41499 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 6 Aug 2022 16:52:10 +0100 Subject: [PATCH 2/3] Fix incorrect result for multi-level lists (issue #275) --- lib/markdown2.py | 11 +++++++++-- test/tm-cases/nested_list.html | 21 +++++++++++++++++++++ test/tm-cases/nested_list.text | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index c9eb76a7..073282fb 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -1798,7 +1798,7 @@ def _list_item_sub(self, match): item = self._run_block_gamut(self._outdent(item)) else: # Recursion for sub-lists: - item = self._do_lists(self._outdent(item)) + item = self._do_lists(self._uniform_outdent(item, min_outdent=' ')[1]) if item.endswith('\n'): item = item[:-1] item = self._run_span_gamut(item) @@ -2457,12 +2457,19 @@ def _outdent(self, text): # Remove one level of line-leading tabs or spaces return self._outdent_re.sub('', text) - def _uniform_outdent(self, text): + def _uniform_outdent(self, text, min_outdent=None): # Removes the smallest common leading indentation from each line # of `text` and returns said indent along with the outdented text. + # The `min_outdent` kwarg only outdents lines that start with at + # least this level of indentation or more. # Find leading indentation of each line ws = re.findall(r'(^[ \t]*)(?:[^ \t\n])', text, re.MULTILINE) + # Sort the indents within bounds + if min_outdent: + # dont use "is not None" here so we avoid iterating over ws + # if min_outdent == '', which would do nothing + ws = [i for i in ws if len(min_outdent) <= len(i)] if not ws: return '', text # Get smallest common leading indent diff --git a/test/tm-cases/nested_list.html b/test/tm-cases/nested_list.html index c0617e42..05851236 100644 --- a/test/tm-cases/nested_list.html +++ b/test/tm-cases/nested_list.html @@ -13,3 +13,24 @@
  • peaches
  • + +

    Slightly more nested list:

    + + diff --git a/test/tm-cases/nested_list.text b/test/tm-cases/nested_list.text index a37a1954..94a2ece1 100644 --- a/test/tm-cases/nested_list.text +++ b/test/tm-cases/nested_list.text @@ -7,3 +7,17 @@ shopping list: + oranges + apples + *peaches* + + +Slightly more nested list: + +* Item 1 + 1. Hello + 2. World +* Item 2 + - Subitem A + - Subitem B following: + + What + + The + + Code +* Item 3 - yes! just a single item \ No newline at end of file From 5ae3f9d5a8aa4f9a1b3390ebe99b66238d9f7a18 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 6 Aug 2022 16:52:57 +0100 Subject: [PATCH 3/3] Update admonitions test case to make tests pass --- test/tm-cases/admonitions.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tm-cases/admonitions.html b/test/tm-cases/admonitions.html index 5961aa55..2b65647c 100644 --- a/test/tm-cases/admonitions.html +++ b/test/tm-cases/admonitions.html @@ -45,8 +45,8 @@
    • Even inside