summaryrefslogtreecommitdiff
path: root/tests/test_syntax/extensions/test_toc.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2019-11-26 11:56:01 -0500
committerGitHub <noreply@github.com>2019-11-26 11:56:01 -0500
commit1f3ec538a2acf25607253fc7c7a992950463931d (patch)
tree9555b3a823958d55943a452a7d8e639a9b08c55f /tests/test_syntax/extensions/test_toc.py
parent3b576bc189764d230cc8fbde773fe232aaa075f3 (diff)
downloadpython-markdown-1f3ec538a2acf25607253fc7c7a992950463931d.tar.gz
Add anchorlink_class and permalink_class options to TOC
Two new configuration options have been added to the toc extension: `anchorlink_class` and `permalink_class` which allows class(es) to be assigned to the `anchorlink` and `permalink` HTML respectively. This allows using icon fonts from CSS for the links. Therefore, an empty string passed to `permalink` now generates an empty `permalink`. Previously no `permalink` would have been generated. Based on #776.
Diffstat (limited to 'tests/test_syntax/extensions/test_toc.py')
-rw-r--r--tests/test_syntax/extensions/test_toc.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/test_syntax/extensions/test_toc.py b/tests/test_syntax/extensions/test_toc.py
index 65223aa..65fc0c2 100644
--- a/tests/test_syntax/extensions/test_toc.py
+++ b/tests/test_syntax/extensions/test_toc.py
@@ -20,6 +20,7 @@ License: BSD (see LICENSE.md for details).
"""
from markdown.test_tools import TestCase
+from markdown.extensions.toc import TocExtension
class TestTOC(TestCase):
@@ -32,3 +33,69 @@ class TestTOC(TestCase):
'<h1 id="escaped_character">escaped_character</h1>',
extensions=['toc']
)
+
+ def testAnchorLinkWithCustomClass(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ # Header 1
+
+ ## Header *2*
+ '''
+ ),
+ self.dedent(
+ '''
+ <h1 id="header-1"><a class="custom" href="#header-1">Header 1</a></h1>
+ <h2 id="header-2"><a class="custom" href="#header-2">Header <em>2</em></a></h2>
+ '''
+ ),
+ extensions=[TocExtension(anchorlink=True, anchorlink_class="custom")]
+ )
+
+ def testAnchorLinkWithCustomClasses(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ # Header 1
+
+ ## Header *2*
+ '''
+ ),
+ self.dedent(
+ '''
+ <h1 id="header-1"><a class="custom1 custom2" href="#header-1">Header 1</a></h1>
+ <h2 id="header-2"><a class="custom1 custom2" href="#header-2">Header <em>2</em></a></h2>
+ '''
+ ),
+ extensions=[TocExtension(anchorlink=True, anchorlink_class="custom1 custom2")]
+ )
+
+ def testPermalinkWithEmptyText(self):
+ self.assertMarkdownRenders(
+ '# Header',
+ '<h1 id="header">' # noqa
+ 'Header' # noqa
+ '<a class="headerlink" href="#header" title="Permanent link"></a>' # noqa
+ '</h1>', # noqa
+ extensions=[TocExtension(permalink="")]
+ )
+
+ def testPermalinkWithCustomClass(self):
+ self.assertMarkdownRenders(
+ '# Header',
+ '<h1 id="header">' # noqa
+ 'Header' # noqa
+ '<a class="custom" href="#header" title="Permanent link">&para;</a>' # noqa
+ '</h1>', # noqa
+ extensions=[TocExtension(permalink=True, permalink_class="custom")]
+ )
+
+ def testPermalinkWithCustomClasses(self):
+ self.assertMarkdownRenders(
+ '# Header',
+ '<h1 id="header">' # noqa
+ 'Header' # noqa
+ '<a class="custom1 custom2" href="#header" title="Permanent link">&para;</a>' # noqa
+ '</h1>', # noqa
+ extensions=[TocExtension(permalink=True, permalink_class="custom1 custom2")]
+ )