Skip to content

Commit

Permalink
Add comprehensive strip_tag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
waylan committed Feb 12, 2024
1 parent caf4f2e commit d7bff9b
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion tests/test_syntax/extensions/test_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""

from markdown.test_tools import TestCase
from markdown.extensions.toc import TocExtension
from markdown.extensions.toc import TocExtension, strip_tags
from markdown.extensions.nl2br import Nl2BrExtension


Expand Down Expand Up @@ -858,3 +858,72 @@ def testHeadingRemoveFootnoteRef(self):
},
extensions=[TocExtension(), 'footnotes']
)


class testStripTags(TestCase):

def testStripElement(self):
self.assertEqual(
strip_tags('foo <em>bar</em>'),
'foo bar'
)

def testStripOpenElement(self):
self.assertEqual(
strip_tags('foo <em>bar'),
'foo bar'
)

def testStripEmptyElement(self):
self.assertEqual(
strip_tags('foo <br />bar'),
'foo bar'
)

def testDontStripOpenBracket(self):
self.assertEqual(
strip_tags('foo < bar'),
'foo < bar'
)

def testDontStripCloseBracket(self):
self.assertEqual(
strip_tags('foo > bar'),
'foo > bar'
)

def testStripCollapseWhitespace(self):
self.assertEqual(
strip_tags('foo <em>\tbar\t</em>'),
'foo bar'
)

def testStripElementWithNewlines(self):
self.assertEqual(
strip_tags('foo <meta content="tag\nwith\nnewlines"> bar'),
'foo bar'
)

def testStripComment(self):
self.assertEqual(
strip_tags('foo <!-- comment --> bar'),
'foo bar'
)

def testStripCommentWithInnerTags(self):
self.assertEqual(
strip_tags('foo <!-- comment with <em> --> bar'),
'foo bar'
)

def testStripCommentInElement(self):
self.assertEqual(
strip_tags('<em>foo <!-- comment --> bar<em>'),
'foo bar'
)

def testDontStripHTMLEntities(self):
self.assertEqual(
strip_tags('foo &lt; &amp; &lt; bar'),
'foo &lt; &amp; &lt; bar'
)

0 comments on commit d7bff9b

Please sign in to comment.