Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/tm-cases/admonitions.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<ul>
<li>Even inside
<aside class="admonition tip">
<strong>tip</strong>
<p>of a list</p>
<strong>tip</strong>
<p>of a list</p>
</aside></li>
</ul>
</aside>
Expand Down
8 changes: 6 additions & 2 deletions test/tm-cases/break_on_newline_excessive_br_tags_in_ul.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ <h2>Conteúdo</h2>
<ul>
<li>O que é estrutura Co-locada (on premises), o que é estrutura híbrida e o que é estrutura em-nuvem?
<ul>
<li>Em Nuvem (cloud based)</li>
<li>Em Nuvem (cloud based)
<ul>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing a quick look at this and it seems wrong because the LIs arent closing. But i'm guessing this is intentional? UL should be nested under the LI before it's closed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Mozilla docs on nesting lists give an example where the nested <ul> is placed as a child of the <li> before closing and I also found this stackoverflow answer that confirms this

<li>Uma estrutura em-nuvem tem todos os seus principais recursos providos por um provedor de serviços em nuvem.
<ul>
<li>Uma definição formal de serviço em nuvem pode ser:</li>
<li>Uma definição formal de serviço em nuvem pode ser:
<ul>
<li>Entrega via internet de um serviço de Tecnologia da Informação, sob demanda, em um modelo de pague-pelo-que-consome.
<ul>
<li>Brown Field é quando você migra um serviço existente</li>
<li>Green field é quando você começa do zero na nuvem, alguns também chamam isto de Cloud </li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul>

<h2>Ordered List</h2>
Expand Down
21 changes: 21 additions & 0 deletions test/tm-cases/nested_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@
<li><em>peaches</em></li>
</ul></li>
</ul>

<p>Slightly more nested list:</p>

<ul>
<li>Item 1
<ol>
<li>Hello</li>
<li>World</li>
</ol></li>
<li>Item 2
<ul>
<li>Subitem A</li>
<li>Subitem B following:
<ul>
<li>What</li>
<li>The</li>
<li>Code</li>
</ul></li>
</ul></li>
<li>Item 3 - yes! just a single item</li>
</ul>
14 changes: 14 additions & 0 deletions test/tm-cases/nested_list.text
Original file line number Diff line number Diff line change
Expand Up @@ -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