From 8111fd3d80f5a9a530323338ac07910bc9e4f653 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Sat, 14 Mar 2015 17:15:06 -0400 Subject: Add Comment support to toc. A etree can contain Comments, PIs or other Elements which do not have a string for a tag. Must always check that a tag is a string before doing string processing on it. Otherwise, things will crash. --- markdown/extensions/toc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index fdfa687..b3cf898 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -17,7 +17,7 @@ from __future__ import absolute_import from __future__ import unicode_literals from . import Extension from ..treeprocessors import Treeprocessor -from ..util import etree, parseBoolValue, AMP_SUBSTITUTE, HTML_PLACEHOLDER_RE +from ..util import etree, parseBoolValue, AMP_SUBSTITUTE, HTML_PLACEHOLDER_RE, string_type import re import unicodedata @@ -231,7 +231,7 @@ class TocTreeprocessor(Treeprocessor): toc_tokens = [] for el in doc.iter(): - if self.header_rgx.match(el.tag): + if isinstance(el.tag, string_type) and self.header_rgx.match(el.tag): self.set_level(el) text = ''.join(el.itertext()).strip() -- cgit v1.2.3