Skip to content

Commit d7bff9b

Browse files
committed
Add comprehensive strip_tag tests
1 parent caf4f2e commit d7bff9b

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

tests/test_syntax/extensions/test_toc.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121

2222
from markdown.test_tools import TestCase
23-
from markdown.extensions.toc import TocExtension
23+
from markdown.extensions.toc import TocExtension, strip_tags
2424
from markdown.extensions.nl2br import Nl2BrExtension
2525

2626

@@ -858,3 +858,72 @@ def testHeadingRemoveFootnoteRef(self):
858858
},
859859
extensions=[TocExtension(), 'footnotes']
860860
)
861+
862+
863+
class testStripTags(TestCase):
864+
865+
def testStripElement(self):
866+
self.assertEqual(
867+
strip_tags('foo <em>bar</em>'),
868+
'foo bar'
869+
)
870+
871+
def testStripOpenElement(self):
872+
self.assertEqual(
873+
strip_tags('foo <em>bar'),
874+
'foo bar'
875+
)
876+
877+
def testStripEmptyElement(self):
878+
self.assertEqual(
879+
strip_tags('foo <br />bar'),
880+
'foo bar'
881+
)
882+
883+
def testDontStripOpenBracket(self):
884+
self.assertEqual(
885+
strip_tags('foo < bar'),
886+
'foo < bar'
887+
)
888+
889+
def testDontStripCloseBracket(self):
890+
self.assertEqual(
891+
strip_tags('foo > bar'),
892+
'foo > bar'
893+
)
894+
895+
def testStripCollapseWhitespace(self):
896+
self.assertEqual(
897+
strip_tags('foo <em>\tbar\t</em>'),
898+
'foo bar'
899+
)
900+
901+
def testStripElementWithNewlines(self):
902+
self.assertEqual(
903+
strip_tags('foo <meta content="tag\nwith\nnewlines"> bar'),
904+
'foo bar'
905+
)
906+
907+
def testStripComment(self):
908+
self.assertEqual(
909+
strip_tags('foo <!-- comment --> bar'),
910+
'foo bar'
911+
)
912+
913+
def testStripCommentWithInnerTags(self):
914+
self.assertEqual(
915+
strip_tags('foo <!-- comment with <em> --> bar'),
916+
'foo bar'
917+
)
918+
919+
def testStripCommentInElement(self):
920+
self.assertEqual(
921+
strip_tags('<em>foo <!-- comment --> bar<em>'),
922+
'foo bar'
923+
)
924+
925+
def testDontStripHTMLEntities(self):
926+
self.assertEqual(
927+
strip_tags('foo &lt; &amp; &lt; bar'),
928+
'foo &lt; &amp; &lt; bar'
929+
)

0 commit comments

Comments
 (0)