src/cm/utils/html.py
changeset 175 4f072edc51a1
parent 154 8cb89c153140
equal deleted inserted replaced
174:805b9195c511 175:4f072edc51a1
     1 """
     1 """
     2 Package to manipulage html chunks
     2 Package to manipulage html chunks
     3 """
     3 """
     4 
     4 
       
     5 from string_utils import strip_cr
     5 from BeautifulSoup import BeautifulSoup, Comment
     6 from BeautifulSoup import BeautifulSoup, Comment
     6 
     7 
     7 def surrond_text_node(html_chunk, start_html, end_html):
     8 def surrond_text_node(html_chunk, start_html, end_html):
     8     """
     9     """
     9     Surround text nodes in html_chunk
    10     Surround text nodes in html_chunk
    14         if text_node.string.strip():
    15         if text_node.string.strip():
    15             text_node.replaceWith(start_html + text_node.string + end_html)
    16             text_node.replaceWith(start_html + text_node.string + end_html)
    16     return unicode(soup)
    17     return unicode(soup)
    17     
    18     
    18 
    19 
    19 # utilities    
    20 #utilities    
    20 def get_text_nodes(soup):
    21 def get_text_nodes(soup):
    21     return soup(text=lambda text:not isinstance(text, Comment))
    22     return soup(text=lambda text:not isinstance(text, Comment))
       
    23 
       
    24 #WARNING behavior changed also for mardown. but really shouldn't hurt 20100212
       
    25 #it is text as received from textarea
       
    26 def on_content_receive(txt, format) :
       
    27     #because textarea content arent packaged the same way on windows IE and linux FF, dhouldn't't hurt to clean it for any format
       
    28     return strip_cr(txt)
       
    29