@@ -629,3 +629,117 @@ def testTocInHeaders(self):
629629 '</div>\n ' # noqa
630630 '<h1 id="toc"><em>[TOC]</em></h1>' # noqa
631631 )
632+
633+ def testPermalink (self ):
634+ """ Test TOC `permalink` feature. """
635+ text = '# Hd 1\n \n ## Hd 2'
636+ md = markdown .Markdown (
637+ extensions = [markdown .extensions .toc .TocExtension (
638+ permalink = True , permalink_title = "PL" )]
639+ )
640+ self .assertEqual (
641+ md .convert (text ),
642+ '<h1 id="hd-1">'
643+ 'Hd 1' # noqa
644+ '<a class="headerlink" href="#hd-1" title="PL">' # noqa
645+ '¶' # noqa
646+ '</a>' # noqa
647+ '</h1>\n '
648+ '<h2 id="hd-2">'
649+ 'Hd 2' # noqa
650+ '<a class="headerlink" href="#hd-2" title="PL">' # noqa
651+ '¶' # noqa
652+ '</a>' # noqa
653+ '</h2>'
654+ )
655+
656+ def testPermalinkLeading (self ):
657+ """ Test TOC `permalink` with `permalink_leading` option. """
658+ text = '# Hd 1\n \n ## Hd 2'
659+ md = markdown .Markdown (extensions = [
660+ markdown .extensions .toc .TocExtension (
661+ permalink = True , permalink_title = "PL" , permalink_leading = True )]
662+ )
663+ self .assertEqual (
664+ md .convert (text ),
665+ '<h1 id="hd-1">'
666+ '<a class="headerlink" href="#hd-1" title="PL">' # noqa
667+ '¶' # noqa
668+ '</a>' # noqa
669+ 'Hd 1' # noqa
670+ '</h1>\n '
671+ '<h2 id="hd-2">'
672+ '<a class="headerlink" href="#hd-2" title="PL">' # noqa
673+ '¶' # noqa
674+ '</a>' # noqa
675+ 'Hd 2' # noqa
676+ '</h2>'
677+ )
678+
679+ def testInlineMarkupPermalink (self ):
680+ """ Test TOC `permalink` with headers containing markup. """
681+ text = '# Code `in` hd'
682+ md = markdown .Markdown (
683+ extensions = [markdown .extensions .toc .TocExtension (
684+ permalink = True , permalink_title = "PL" )]
685+ )
686+ self .assertEqual (
687+ md .convert (text ),
688+ '<h1 id="code-in-hd">'
689+ 'Code <code>in</code> hd' # noqa
690+ '<a class="headerlink" href="#code-in-hd" title="PL">' # noqa
691+ '¶' # noqa
692+ '</a>' # noqa
693+ '</h1>'
694+ )
695+
696+ def testInlineMarkupPermalinkLeading (self ):
697+ """ Test TOC `permalink_leading` with headers containing markup. """
698+ text = '# Code `in` hd'
699+ md = markdown .Markdown (extensions = [
700+ markdown .extensions .toc .TocExtension (
701+ permalink = True , permalink_title = "PL" , permalink_leading = True )]
702+ )
703+ self .assertEqual (
704+ md .convert (text ),
705+ '<h1 id="code-in-hd">'
706+ '<a class="headerlink" href="#code-in-hd" title="PL">' # noqa
707+ '¶' # noqa
708+ '</a>' # noqa
709+ 'Code <code>in</code> hd' # noqa
710+ '</h1>'
711+ )
712+
713+
714+ class TestSmarty (unittest .TestCase ):
715+ def setUp (self ):
716+ config = {
717+ 'smarty' : [
718+ ('smart_angled_quotes' , True ),
719+ ('substitutions' , {
720+ 'ndash' : '\u2013 ' ,
721+ 'mdash' : '\u2014 ' ,
722+ 'ellipsis' : '\u2026 ' ,
723+ 'left-single-quote' : '‚' , # `sb` is not a typo!
724+ 'right-single-quote' : '‘' ,
725+ 'left-double-quote' : '„' ,
726+ 'right-double-quote' : '“' ,
727+ 'left-angle-quote' : '[' ,
728+ 'right-angle-quote' : ']' ,
729+ }),
730+ ]
731+ }
732+ self .md = markdown .Markdown (
733+ extensions = ['smarty' ],
734+ extension_configs = config
735+ )
736+
737+ def testCustomSubstitutions (self ):
738+ text = """<< The "Unicode char of the year 2014"
739+ is the 'mdash': ---
740+ Must not be confused with 'ndash' (--) ... >>
741+ """
742+ correct = """<p>[ The „Unicode char of the year 2014“
743+ is the ‚mdash‘: \u2014
744+ Must not be confused with ‚ndash‘ (\u2013 ) \u2026 ]</p>"""
745+ self .assertEqual (self .md .convert (text ), correct )
0 commit comments