MCPcopy Index your code
hub / github.com/clips/pattern / test_plaintext

Method test_plaintext

test/test_web.py:406–438  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

404 print "pattern.web.collapse_linebreaks()"
405
406 def test_plaintext(self):
407 # Assert plaintext:
408 # - strip <script>, <style>, <form>, <!-- --> elements,
409 # - strip tags,
410 # - decode entities,
411 # - collapse whitespace,
412 html = """
413 <html>
414 <head>
415 <title>tags &amp; things</title>
416 </head>
417 <body>
418 <div id="content"> \n\n\n\
419 <!-- main content -->
420 <script type="text/javascript>"alert(0);</script>
421 <h1>title1</h1>
422 <h2>title2</h2>
423 <p>paragraph1</p>
424 <p>paragraph2 <a href="http://www.domain.com" onclick="alert(0);">link</a></p>
425 <ul>
426 <li>item1&nbsp;&nbsp;&nbsp;xxx</li>
427 <li>item2</li>
428 <ul>
429 </div>
430 <br />
431 <br />
432 </body>
433 </html>
434 """
435 self.assertEqual(web.plaintext(html, keep={"a": "href"}),
436 u"tags & things\n\ntitle1\n\ntitle2\n\nparagraph1\n\nparagraph2 " + \
437 u"<a href=\"http://www.domain.com\">link</a>\n\n* item1 xxx\n* item2")
438 print "pattern.web.plaintext()"
439
440#---------------------------------------------------------------------------------------------------
441

Callers

nothing calls this directly

Calls 1

plaintextMethod · 0.45

Tested by

no test coverage detected