diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2018-09-05 15:54:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-05 15:54:16 -0400 |
commit | f51125d01b88067d8523e9706cfa4558b3808222 (patch) | |
tree | a3bfba21a78865d023129f20e8ca2395d583354f /tests | |
parent | da68eb57a1f88b02543950f623a64ec6186d2ab2 (diff) | |
download | markdown-f51125d01b88067d8523e9706cfa4558b3808222.tar.gz markdown-f51125d01b88067d8523e9706cfa4558b3808222.tar.bz2 markdown-f51125d01b88067d8523e9706cfa4558b3808222.zip |
Support custom labels in TOC. (#700)
New `toc_tokens` attribute on Markdown class.
Contains the raw tokens used to build the Table of Contents. Users can
use this to build their own custom Table of Contents rather than needing
to parse the HTML available on the `toc` attribute of the Markdown
class.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_extensions.py | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/tests/test_extensions.py b/tests/test_extensions.py index 532ed6f..5489887 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -852,24 +852,40 @@ class TestTOC(TestCaseWithAssertStartsWith): def testWithAttrList(self): """ Test TOC with attr_list Extension. """ md = markdown.Markdown(extensions=['toc', 'attr_list']) - text = '# Header 1\n\n## Header 2 { #foo }' + text = '# Header 1\n\n## Header 2 { #foo }\n\n## Header 3 { data-toc-label="Foo Bar"}' self.assertEqual( md.convert(text), '<h1 id="header-1">Header 1</h1>\n' - '<h2 id="foo">Header 2</h2>' + '<h2 id="foo">Header 2</h2>\n' + '<h2 id="header-3">Header 3</h2>' ) 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="#foo">Header 2</a></li>\n' # noqa - '</ul>\n' # noqa - '</li>\n' # noqa - '</ul>\n' # noqa + '<ul>\n' # noqa + '<li><a href="#header-1">Header 1</a>' # noqa + '<ul>\n' # noqa + '<li><a href="#foo">Header 2</a></li>\n' # noqa + '<li><a href="#header-3">Foo Bar</a></li>\n' # noqa + '</ul>\n' # noqa + '</li>\n' # noqa + '</ul>\n' # noqa '</div>\n' ) + self.assertEqual( + md.toc_tokens, + [ + { + 'level': 1, + 'id': 'header-1', + 'name': 'Header 1', + 'children': [ + {'level': 2, 'id': 'foo', 'name': 'Header 2', 'children': []}, + {'level': 2, 'id': 'header-3', 'name': 'Foo Bar', 'children': []} + ] + } + ] + ) def testUniqueFunc(self): """ Test 'unique' function. """ |