aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2015-01-01 13:25:04 -0500
committerWaylan Limberg <waylan.limberg@icloud.com>2015-01-01 13:25:04 -0500
commit5389174da277ca13f9b430c2cc8db6d011499205 (patch)
treeb158cc4671808a94d240f0ce6dbe2b864b0a5fa5 /tests
parentfef6e285d28e25cf4acb93f0ef470fd690507cfa (diff)
downloadmarkdown-5389174da277ca13f9b430c2cc8db6d011499205.tar.gz
markdown-5389174da277ca13f9b430c2cc8db6d011499205.tar.bz2
markdown-5389174da277ca13f9b430c2cc8db6d011499205.zip
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_extensions.py159
1 files changed, 105 insertions, 54 deletions
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):
'<h1 id="some-header">Some Header</h1>'
)
- 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),
- '<h1 id="header">Header</h1>\n'
- '<h1 id="header_1">Header</h1>\n'
- '<h1 id="header_2">Header</h1>'
- )
-
- def testBaseLevel(self):
- """ Test Header Base Level. """
-
- text = '#Some Header\n## Next Level'
- self.assertEqual(
- markdown.markdown(text, [markdown.extensions.headerid.HeaderIdExtension(level=3)]),
- '<h3 id="some-header">Some Header</h3>\n'
- '<h4 id="next-level">Next Level</h4>'
- )
-
- def testHeaderInlineMarkup(self):
- """ Test Header IDs with inline markup. """
-
- text = '#Some *Header* with [markup](http://example.com).'
- self.assertEqual(
- self.md.convert(text),
- '<h1 id="some-header-with-markup">Some <em>Header</em> with '
- '<a href="http://example.com">markup</a>.</h1>'
- )
-
- def testHtmlEntities(self):
- """ Test HeaderIDs with HTML Entities. """
- text = '# Foo &amp; bar'
- self.assertEqual(
- self.md.convert(text),
- '<h1 id="foo-bar">Foo &amp; bar</h1>'
- )
-
- def testRawHtml(self):
- """ Test HeaderIDs with raw HTML. """
- text = '# Foo <b>Bar</b> Baz.'
- self.assertEqual(
- self.md.convert(text),
- '<h1 id="foo-bar-baz">Foo <b>Bar</b> Baz.</h1>'
- )
-
def testNoAutoIds(self):
""" Test HeaderIDs with no auto generated IDs. """
@@ -733,6 +679,41 @@ class TestTOC(unittest.TestCase):
'</div>\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),
+ '<div class="toc">\n'
+ '<ul>\n' # noqa
+ '<li><a href="#header-1">Header 1</a>' # noqa
+ '<ul>\n' # noqa
+ '<li><a href="#header-2">Header 2</a></li>\n' # noqa
+ '</ul>\n' # noqa
+ '</li>\n' # noqa
+ '</ul>\n' # noqa
+ '</div>\n'
+ '<h1 id="header-1">Header 1</h1>\n'
+ '<h2 id="header-2">Header 2</h2>'
+ )
+
+ 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),
+ '<p>[TOC]</p>\n'
+ '<h1 id="header-1">Header 1</h1>\n'
+ '<h2 id="header-2">Header 2</h2>'
+ )
+ self.assertTrue(md.toc.startswith('<div class="toc">'))
+
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),
+ '<h1 id="header">Header</h1>\n'
+ '<h1 id="header_1">Header</h1>\n'
+ '<h1 id="header_2">Header</h1>'
+ )
+
+ def testHtmlEntities(self):
+ """ Test Headers with HTML Entities. """
+ text = '# Foo &amp; bar'
+ self.assertEqual(
+ self.md.convert(text),
+ '<h1 id="foo-bar">Foo &amp; bar</h1>'
+ )
+
+ def testRawHtml(self):
+ """ Test Headers with raw HTML. """
+ text = '# Foo <b>Bar</b> Baz.'
+ self.assertEqual(
+ self.md.convert(text),
+ '<h1 id="foo-bar-baz">Foo <b>Bar</b> Baz.</h1>'
+ )
+
+ 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),
+ '<h5 id="some-header">Some Header</h5>\n'
+ '<h6 id="next-level">Next Level</h6>\n'
+ '<h6 id="too-high">Too High</h6>'
+ )
+ self.assertEqual(
+ md.toc,
+ '<div class="toc">\n'
+ '<ul>\n' # noqa
+ '<li><a href="#some-header">Some Header</a>' # noqa
+ '<ul>\n' # noqa
+ '<li><a href="#next-level">Next Level</a></li>\n' # noqa
+ '<li><a href="#too-high">Too High</a></li>\n' # noqa
+ '</ul>\n' # noqa
+ '</li>\n' # noqa
+ '</ul>\n' # noqa
+ '</div>\n'
+ )
+
+ def testHeaderInlineMarkup(self):
+ """ Test Headers with inline markup. """
+
+ text = '#Some *Header* with [markup](http://example.com).'
+ self.assertEqual(
+ self.md.convert(text),
+ '<h1 id="some-header-with-markup">Some <em>Header</em> with '
+ '<a href="http://example.com">markup</a>.</h1>'
+ )
+
def testAnchorLink(self):
""" Test TOC Anchorlink. """
md = markdown.Markdown(
@@ -783,6 +827,13 @@ class TestTOC(unittest.TestCase):
'</div>\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):