aboutsummaryrefslogtreecommitdiffstats
path: root/tests
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 /tests
parentae914abeac5d5527e1ada500fe7faf545fbb638c (diff)
downloadmarkdown-a9f1171d3bd7908fbcfd3df0b7b36c9dd7c4607c.tar.gz
markdown-a9f1171d3bd7908fbcfd3df0b7b36c9dd7c4607c.tar.bz2
markdown-a9f1171d3bd7908fbcfd3df0b7b36c9dd7c4607c.zip
Add toc_depth parameter to toc extension
Diffstat (limited to 'tests')
-rw-r--r--tests/test_extensions.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index 35eaf1d..7e2dad1 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -894,6 +894,60 @@ class TestTOC(TestCaseWithAssertStartsWith):
'<h1 id="toc"><em>[TOC]</em></h1>' # noqa
)
+ def testMaxLevel(self):
+ """ Test toc_depth setting """
+ md = markdown.Markdown(
+ extensions=[markdown.extensions.toc.TocExtension(toc_depth=2)]
+ )
+ text = '# Header 1\n\n## Header 2\n\n###Header 3 not in TOC'
+ self.assertEqual(
+ md.convert(text),
+ '<h1 id="header-1">Header 1</h1>\n'
+ '<h2 id="header-2">Header 2</h2>\n'
+ '<h3>Header 3 not in TOC</h3>'
+ )
+ self.assertEqual(
+ md.toc,
+ '<div class="toc">\n'
+ '<ul>\n' # noqa
+ '<li><a href="#header-1">Header 1</a>' # noqa
+ '<ul>\n' # noqa
+ '<li><a href="#header-2">Header 2</a></li>\n' # noqa
+ '</ul>\n' # noqa
+ '</li>\n' # noqa
+ '</ul>\n' # noqa
+ '</div>\n'
+ )
+
+ self.assertNotIn("Header 3", md.toc)
+
+ def testMaxLevelwithBaseLevel(self):
+ """ Test toc_depth setting together with baselevel """
+ md = markdown.Markdown(
+ extensions=[markdown.extensions.toc.TocExtension(toc_depth=3,
+ baselevel=2)]
+ )
+ text = '# Some Header\n\n## Next Level\n\n### Too High'
+ self.assertEqual(
+ md.convert(text),
+ '<h2 id="some-header">Some Header</h2>\n'
+ '<h3 id="next-level">Next Level</h3>\n'
+ '<h4>Too High</h4>'
+ )
+ self.assertEqual(
+ md.toc,
+ '<div class="toc">\n'
+ '<ul>\n' # noqa
+ '<li><a href="#some-header">Some Header</a>' # noqa
+ '<ul>\n' # noqa
+ '<li><a href="#next-level">Next Level</a></li>\n' # noqa
+ '</ul>\n' # noqa
+ '</li>\n' # noqa
+ '</ul>\n' # noqa
+ '</div>\n'
+ )
+ self.assertNotIn("Too High", md.toc)
+
class TestSmarty(unittest.TestCase):
def setUp(self):