aboutsummaryrefslogtreecommitdiffstats
path: root/markdown
diff options
context:
space:
mode:
authorJesús Fernández <fernandez.cuesta@gmail.com>2015-09-01 17:29:37 +0200
committerWaylan Limberg <waylan.limberg@icloud.com>2018-07-24 15:07:14 -0400
commita9f1171d3bd7908fbcfd3df0b7b36c9dd7c4607c (patch)
treeb5a43276ec2e4efec137bd56e1800c9de5ab9a93 /markdown
parentae914abeac5d5527e1ada500fe7faf545fbb638c (diff)
downloadmarkdown-a9f1171d3bd7908fbcfd3df0b7b36c9dd7c4607c.tar.gz
markdown-a9f1171d3bd7908fbcfd3df0b7b36c9dd7c4607c.tar.bz2
markdown-a9f1171d3bd7908fbcfd3df0b7b36c9dd7c4607c.zip
Add toc_depth parameter to toc extension
Diffstat (limited to 'markdown')
-rw-r--r--markdown/extensions/toc.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py
index 0e9b2b9..5783f3d 100644
--- a/markdown/extensions/toc.py
+++ b/markdown/extensions/toc.py
@@ -134,8 +134,8 @@ class TocTreeprocessor(Treeprocessor):
self.use_permalinks = parseBoolValue(config["permalink"], False)
if self.use_permalinks is None:
self.use_permalinks = config["permalink"]
-
self.header_rgx = re.compile("[Hh][123456]")
+ self.toc_depth = config["toc_depth"]
def iterparent(self, node):
''' Iterator wrapper to get allowed parent and child all at once. '''
@@ -234,6 +234,8 @@ class TocTreeprocessor(Treeprocessor):
for el in doc.iter():
if isinstance(el.tag, string_type) and self.header_rgx.match(el.tag):
self.set_level(el)
+ if int(el.tag[-1]) > int(self.toc_depth):
+ continue
text = ''.join(el.itertext()).strip()
# Do not override pre-existing ids
@@ -285,7 +287,10 @@ class TocExtension(Extension):
"slugify": [slugify,
"Function to generate anchors based on header text - "
"Defaults to the headerid ext's slugify function."],
- 'separator': ['-', 'Word separator. Defaults to "-".']
+ 'separator': ['-', 'Word separator. Defaults to "-".'],
+ "toc_depth": [6,
+ "Define up to which section level n (<h1>..<hn>) to "
+ "include in the TOC"]
}
super(TocExtension, self).__init__(**kwargs)