Skip to content
Closed
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
25 changes: 20 additions & 5 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,15 +1508,23 @@ def _do_lists(self, text):
(\n)? # leading line = \1
(^[ \t]*) # leading whitespace = \2
(?P<marker>%s) [ \t]+ # list marker = \3
((?:.+?) # list item text = \4
(\n{1,2})) # eols = \5
(\[[\ x]\])[ \t]+ # tasklist marker = \4
((?:.+?) # list item text = \5
(\n{1,2})) # eols = \6
(?= \n* (\Z | \2 (?P<next_marker>%s) [ \t]+))
''' % (_marker_any, _marker_any),
re.M | re.X | re.S)

_task_list_warpper_str = r''' <li class="task-list-item">
<p><input type="checkbox" class="task-list-item-checkbox" %sdisabled>
%s
</p>
</li>
'''

_last_li_endswith_two_eols = False
def _list_item_sub(self, match):
item = match.group(4)
item = match.group(5)
leading_line = match.group(1)
if leading_line or "\n\n" in item or self._last_li_endswith_two_eols:
item = self._run_block_gamut(self._outdent(item))
Expand All @@ -1526,8 +1534,15 @@ def _list_item_sub(self, match):
if item.endswith('\n'):
item = item[:-1]
item = self._run_span_gamut(item)
self._last_li_endswith_two_eols = (len(match.group(5)) == 2)
return "<li>%s</li>\n" % item
self._last_li_endswith_two_eols = (len(match.group(6)) == 2)
if "tasklist" in self.extras:
task_list_marker = match.group(4)
if task_list_marker == '[x]':
return self._task_list_warpper_str % ('checked ', item)
elif task_list_marker == '[ ]':
return self._task_list_warpper_str % ('', item)
else:
return "<li>%s</li>\n" % item

def _process_list_items(self, list_str):
# Process the contents of a single ordered or unordered list,
Expand Down