From f51125d01b88067d8523e9706cfa4558b3808222 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Wed, 5 Sep 2018 15:54:16 -0400 Subject: 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. --- tests/test_extensions.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'tests') 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), '

Header 1

\n' - '

Header 2

' + '

Header 2

\n' + '

Header 3

' ) self.assertEqual( md.toc, '
\n' - '\n' # noqa + '\n' # noqa '
\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. """ -- cgit v1.2.3