Did I find the right examples for you? yes no

All Samples(10)  |  Call(6)  |  Derive(0)  |  Import(4)

        def strip_html(html_code):
    """
    Delete whitespace from html code. Doesn't recordnize preformatted blocks!

    >>> strip_html(' 

one \\n two

') '

one two

' >>> strip_html('

bold italics

') '

bold italics

' >>> strip_html('
  • Force
    \\n linebreak
  • ') '
  • Force
    linebreak
  • ' >>> strip_html('one two \\n \\n three \\n ') 'one two three ' >>> strip_html('

    a foobar

    ') '

    a foobar

    ' >>> strip_html('

    a

     preformated area 
    foo

    ') '

    a

    preformated area
    foo

    ' >>> strip_html('

    a image.

    ') '

    a image.

    ' """ def strip_tag(match): block = match.group(0) end_tag = match.group("end") in ("/", "/") startend_tag = match.group("startend") in ("/", "/") tag = match.group("tag") # print("_"*40) # print(match.groupdict()) # print("block.......: %r" % block) # print("end_tag.....:", end_tag) # print("startend_tag:", startend_tag) # print("tag.........: %r" % tag) if tag in BLOCK_TAGS: return block.strip() space_start = block.startswith(" ") space_end = block.endswith(" ") result = block.strip() if end_tag: # It's a normal end tag e.g.: if space_start or space_end: result += " " elif startend_tag: # It's a closed start tag e.g.:
    if space_start: # there was space before the tag result = " " + result if space_end: # there was space after the tag result += " " else: # a start tag e.g.: if space_start or space_end: result = " " + result return result data = html_code.strip() clean_data = " ".join([line.strip() for line in data.split("\n")]) clean_data = strip_html_regex.sub(strip_tag, clean_data) return clean_data


    src/p/y/python-creole-1.1.1/creole/html_parser/parser.py   python-creole(Download)
     
    from creole.html_parser.config import BLOCK_TAGS, IGNORE_TAGS
    from creole.html_tools.strip_html import strip_html
    from creole.py3compat import TEXT_TYPE, BINARY_TYPE
    from creole.shared.document_tree import DocNode, DebugList
    
     
            # Delete whitespace from html code
            data = strip_html(data)
     
            if self.debugging:
    

    src/p/y/python-creole-HEAD/creole/html_parser/parser.py   python-creole(Download)
     
    from creole.html_parser.config import BLOCK_TAGS, IGNORE_TAGS
    from creole.html_tools.strip_html import strip_html
    from creole.py3compat import TEXT_TYPE, BINARY_TYPE
    from creole.shared.document_tree import DocNode, DebugList
    
     
            # Delete whitespace from html code
            data = strip_html(data)
     
            if self.debugging:
    

    src/p/y/python-creole-HEAD/creole/tests/test_TODOs.py   python-creole(Download)
     
    from creole.tests.utils.base_unittest import BaseCreoleTest
    from creole.html_tools.strip_html import strip_html
     
     
    class StripHtml(unittest.TestCase):
        def test_not_closed_image_tag(self):
            output = strip_html('<p>a <img src="/image.jpg"> image.</p>')
    
        def test_remove_linebreak(self):
            output = strip_html('<strong>foo</strong>\n<ul><li>one</li></ul>')
            self.assertEqual(output, '<strong>foo</strong><ul><li>one</li></ul>')
     
     
    

    src/p/y/python-creole-1.1.1/creole/tests/test_TODOs.py   python-creole(Download)
     
    from creole.tests.utils.base_unittest import BaseCreoleTest
    from creole.html_tools.strip_html import strip_html
     
     
    class StripHtml(unittest.TestCase):
        def test_not_closed_image_tag(self):
            output = strip_html('<p>a <img src="/image.jpg"> image.</p>')
    
        def test_remove_linebreak(self):
            output = strip_html('<strong>foo</strong>\n<ul><li>one</li></ul>')
            self.assertEqual(output, '<strong>foo</strong><ul><li>one</li></ul>')