Repository: lepture/mistune

Issue:
Task lists cannot be nested
Task lists apparently cannot be nested (tested with master and 2.0.0rc1):

```py
>>> mistune.create_markdown(plugins=['task_lists'])('* [ ] task\n  * [ ] subtask')
'<ul>\n<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled/>task<ul>\n<li>[ ] subtask</li>\n</ul>\n</li>\n</ul>\n'
```

Note that the checkbox in the sublist isn't recognized. Since GitHub [allows task lists to be nested arbitrarily](https://github.github.com/gfm/#task-list-items-extension-), Mistune should probably also support this.

* [ ] nested task lists in mistune
  * [ ] agree that this should be fixed
  * [ ] fix it



Comments:

Patch:
diff --git a/mistune/plugins/task_lists.py b/mistune/plugins/task_lists.py
index 8f7997c..3094ea7 100644
--- a/mistune/plugins/task_lists.py
+++ b/mistune/plugins/task_lists.py
@@ -7,11 +7,7 @@ TASK_LIST_ITEM = re.compile(r'^(\[[ xX]\])\s+')
 
 
 def task_lists_hook(md, tokens, state):
-    for tok in tokens:
-        if tok['type'] == 'list':
-            for item in tok['children']:
-                _rewrite_list_item(item)
-    return tokens
+    return _rewrite_all_list_items(tokens)
 
 
 def render_ast_task_list_item(children, level, checked):
@@ -50,10 +46,16 @@ def plugin_task_lists(md):
         md.renderer.register('task_list_item', render_ast_task_list_item)
 
 
-def _rewrite_list_item(item):
-    if item['type'] != 'list_item':
-        return
+def _rewrite_all_list_items(tokens):
+    for tok in tokens:
+        if tok['type'] == 'list_item':
+            _rewrite_list_item(tok)
+        if 'children' in tok.keys():
+            _rewrite_all_list_items(tok['children'])
+    return tokens
+
 
+def _rewrite_list_item(item):
     children = item['children']
     if children:
         first_child = children[0]


Test patch:
diff --git a/tests/fixtures/task_lists.txt b/tests/fixtures/task_lists.txt
index e8c1c7b..c1760ac 100644
--- a/tests/fixtures/task_lists.txt
+++ b/tests/fixtures/task_lists.txt
@@ -62,3 +62,47 @@
 over two lines</li>
 </ul>
 ````````````````````````````````
+
+```````````````````````````````` example
+- [ ] foo
+  - [x] bar
+  - [ ] baz
+.
+<ul>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled/>foo<ul>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled checked/>bar</li>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled/>baz</li>
+</ul>
+</li>
+</ul>
+````````````````````````````````
+
+```````````````````````````````` example
+1. [ ] foo
+   1. [ ] bar
+   2. [ ] baz
+.
+<ol>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled/>foo<ol>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled/>bar</li>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled/>baz</li>
+</ol>
+</li>
+</ol>
+````````````````````````````````
+
+```````````````````````````````` example
+> - [ ] foo
+>   - [x] bar
+>   - [ ] baz
+.
+<blockquote>
+<ul>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled/>foo<ul>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled checked/>bar</li>
+<li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled/>baz</li>
+</ul>
+</li>
+</ul>
+</blockquote>
+````````````````````````````````
\ No newline at end of file