From 803ab63609d6a148b01d6afc12f841501a5fd84c Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Thu, 17 Mar 2016 18:14:06 +0100 Subject: toc: Remove children from header element after iterating Removing items while iterating can result in wrong behavior. Refs #461. --- markdown/extensions/toc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index b3cf898..56db33c 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -180,7 +180,8 @@ class TocTreeprocessor(Treeprocessor): c.text = "" for elem in c: anchor.append(elem) - c.remove(elem) + while c: + c.remove(c[0]) c.append(anchor) def add_permalink(self, c, elem_id): -- cgit v1.2.3