aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/extensions/toc.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py
index ce0cd8d..2fa5ce1 100644
--- a/markdown/extensions/toc.py
+++ b/markdown/extensions/toc.py
@@ -95,11 +95,15 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
link.attrib["href"] = '#' + id
if int(self.config["anchorlink"]):
- anchor = etree.SubElement(c, "a")
- anchor.text = text
+ anchor = etree.Element("a")
+ anchor.text = c.text
anchor.attrib["href"] = "#" + id
anchor.attrib["class"] = "toclink"
c.text = ""
+ for elem in c.getchildren():
+ anchor.append(elem)
+ c.remove(elem)
+ c.append(anchor)
list_stack[-1].append(last_li)