From 5389174da277ca13f9b430c2cc8db6d011499205 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 1 Jan 2015 13:25:04 -0500 Subject: HeaderId Extension marked as Pending Deprecation. Use the Table of Contents Extension instead. The HeaderId Extension will raise a PendingDeprecationWarning. The last few features of the HeaderID extension were mirgrated to TOC including the baselevel and separator config options. Also, the marker config option of TOC can be set to an empty string to disable searching for a marker. The `slugify`, `unique` and `stashedHTML2text` functions are now defined in the TOC extension in preperation for the HeaderId extension being removed. All coresponding tests are now run against the TOC Extension. The meta-data support of the HeaderId Extension was not migrated and no plan exists to make that migration. The `forceid` config option makes no sense in the TOC Extension and the only other config setting supported by meta-data was the `header_level`. However, as that depends on the template, it makes more sense to not be defined at the document level. --- tests/test_extensions.py | 159 +++++++++++++++++++++++++++++++---------------- 1 file changed, 105 insertions(+), 54 deletions(-) (limited to 'tests') diff --git a/tests/test_extensions.py b/tests/test_extensions.py index dae8829..6642921 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -394,60 +394,6 @@ class TestHeaderId(unittest.TestCase): '

Some Header

' ) - def testUniqueFunc(self): - """ Test 'unique' function. """ - from markdown.extensions.headerid import unique - ids = set(['foo']) - self.assertEqual(unique('foo', ids), 'foo_1') - self.assertEqual(ids, set(['foo', 'foo_1'])) - - def testUniqueIds(self): - """ Test Unique IDs. """ - - text = '#Header\n#Header\n#Header' - self.assertEqual( - self.md.convert(text), - '

Header

\n' - '

Header

\n' - '

Header

' - ) - - def testBaseLevel(self): - """ Test Header Base Level. """ - - text = '#Some Header\n## Next Level' - self.assertEqual( - markdown.markdown(text, [markdown.extensions.headerid.HeaderIdExtension(level=3)]), - '

Some Header

\n' - '

Next Level

' - ) - - def testHeaderInlineMarkup(self): - """ Test Header IDs with inline markup. """ - - text = '#Some *Header* with [markup](http://example.com).' - self.assertEqual( - self.md.convert(text), - '

Some Header with ' - 'markup.

' - ) - - def testHtmlEntities(self): - """ Test HeaderIDs with HTML Entities. """ - text = '# Foo & bar' - self.assertEqual( - self.md.convert(text), - '

Foo & bar

' - ) - - def testRawHtml(self): - """ Test HeaderIDs with raw HTML. """ - text = '# Foo Bar Baz.' - self.assertEqual( - self.md.convert(text), - '

Foo Bar Baz.

' - ) - def testNoAutoIds(self): """ Test HeaderIDs with no auto generated IDs. """ @@ -733,6 +679,41 @@ class TestTOC(unittest.TestCase): '\n' ) + def testAlternateMarker(self): + """ Test TOC with user defined marker. """ + md = markdown.Markdown( + extensions=[markdown.extensions.toc.TocExtension(marker='{{marker}}')] + ) + text = '{{marker}}\n\n# Header 1\n\n## Header 2' + self.assertEqual( + md.convert(text), + '
\n' + '\n' # noqa + '
\n' + '

Header 1

\n' + '

Header 2

' + ) + + def testDisabledMarker(self): + """ Test TOC with disabled marker. """ + md = markdown.Markdown( + extensions=[markdown.extensions.toc.TocExtension(marker='')] + ) + text = '[TOC]\n\n# Header 1\n\n## Header 2' + self.assertEqual( + md.convert(text), + '

[TOC]

\n' + '

Header 1

\n' + '

Header 2

' + ) + self.assertTrue(md.toc.startswith('
')) + def testReset(self): """ Test TOC Reset. """ self.assertEqual(self.md.toc, '') @@ -741,6 +722,69 @@ class TestTOC(unittest.TestCase): self.md.reset() self.assertEqual(self.md.toc, '') + def testUniqueIds(self): + """ Test Unique IDs. """ + + text = '#Header\n#Header\n#Header' + self.assertEqual( + self.md.convert(text), + '

Header

\n' + '

Header

\n' + '

Header

' + ) + + def testHtmlEntities(self): + """ Test Headers with HTML Entities. """ + text = '# Foo & bar' + self.assertEqual( + self.md.convert(text), + '

Foo & bar

' + ) + + def testRawHtml(self): + """ Test Headers with raw HTML. """ + text = '# Foo Bar Baz.' + self.assertEqual( + self.md.convert(text), + '

Foo Bar Baz.

' + ) + + def testBaseLevel(self): + """ Test Header Base Level. """ + md = markdown.Markdown( + extensions=[markdown.extensions.toc.TocExtension(baselevel=5)] + ) + text = '# Some Header\n\n## Next Level\n\n### Too High' + self.assertEqual( + md.convert(text), + '
Some Header
\n' + '
Next Level
\n' + '
Too High
' + ) + self.assertEqual( + md.toc, + '
\n' + '\n' # noqa + '
\n' + ) + + def testHeaderInlineMarkup(self): + """ Test Headers with inline markup. """ + + text = '#Some *Header* with [markup](http://example.com).' + self.assertEqual( + self.md.convert(text), + '

Some Header with ' + 'markup.

' + ) + def testAnchorLink(self): """ Test TOC Anchorlink. """ md = markdown.Markdown( @@ -783,6 +827,13 @@ class TestTOC(unittest.TestCase): '
\n' ) + def testUniqueFunc(self): + """ Test 'unique' function. """ + from markdown.extensions.toc import unique + ids = set(['foo']) + self.assertEqual(unique('foo', ids), 'foo_1') + self.assertEqual(ids, set(['foo', 'foo_1'])) + class TestSmarty(unittest.TestCase): def setUp(self): -- cgit v1.2.3