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
1 change: 1 addition & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ UNRELEASED
* Feature #318: Make padded tables more similar to pandoc's pipe_tables.
* Add support for Python 3.9.
* Fix extra line breaks inside html link text (between '[' and ']')
* Fix #344: indent ``<ul>`` inside ``<ol>`` three spaces instead of two to comply with CommonMark, GFM, etc.

2020.1.16
=========
Expand Down
16 changes: 12 additions & 4 deletions html2text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,19 @@ def link_url(self: HTML2Text, link: str, title: str = "") -> None:
else:
li = ListElement("ul", 0)
if self.google_doc:
nest_count = self.google_nest_count(tag_style)
self.o(" " * self.google_nest_count(tag_style))
else:
nest_count = len(self.list)
# TODO: line up <ol><li>s > 9 correctly.
self.o(" " * nest_count)
# Indent two spaces per list, except use three spaces for an
# unordered list inside an ordered list.
# https://spec.commonmark.org/0.28/#motivation
# TODO: line up <ol><li>s > 9 correctly.
parent_list = None
for list in self.list:
self.o(
" " if parent_list == "ol" and list.name == "ul" else " "
)
parent_list = list.name

if li.name == "ul":
self.o(self.ul_item_mark + " ")
elif li.name == "ol":
Expand Down
20 changes: 20 additions & 0 deletions test/mixed_nested_lists.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ol>
<li>ordered</li>
<li>...</li>
<ul>
<li>unordered</li>
<li>...</li>
</ul>
<li>end</li>
</ol>

<ul>
<li>unordered</li>
<li>...</li>
<ol>
<li>ordered</li>
<li>...</li>
</ol>
<li>end</li>
</ul>

12 changes: 12 additions & 0 deletions test/mixed_nested_lists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1. ordered
2. ...
* unordered
* ...
3. end

* unordered
* ...
1. ordered
2. ...
* end