diff --git a/lib/markdown2.py b/lib/markdown2.py index bfe9abb5..19ed5512 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -1508,15 +1508,23 @@ def _do_lists(self, text): (\n)? # leading line = \1 (^[ \t]*) # leading whitespace = \2 (?P%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%s) [ \t]+)) ''' % (_marker_any, _marker_any), re.M | re.X | re.S) + _task_list_warpper_str = r'''
  • +

    + %s +

    +
  • +''' + _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)) @@ -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 "
  • %s
  • \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 "
  • %s
  • \n" % item def _process_list_items(self, list_str): # Process the contents of a single ordered or unordered list,