src/cm/utils/html.py
author Simon Descarpentries <sid@sopinspace.com>
Wed, 30 Oct 2013 18:08:42 +0100
changeset 556 69503659fe8f
parent 175 4f072edc51a1
permissions -rw-r--r--
[c_selection.js] If safari_mobile, get current selection from a previously created global variable [c_sync.js] ref where the safari_mobile global is used [c_text_view_comments.js] if safari_mobile update selection also on selectionChange event [text_view_comments.html] if safari_mobile store a clone of the current selection on each selectionChange set layout width to 99% to improve display factorize safari mobile detection code

"""
Package to manipulage html chunks
"""

from string_utils import strip_cr
from BeautifulSoup import BeautifulSoup, Comment

def surrond_text_node(html_chunk, start_html, end_html):
    """
    Surround text nodes in html_chunk
    """
    soup = BeautifulSoup(html_chunk)
    text_nodes = get_text_nodes(soup)
    for text_node in text_nodes:        
        if text_node.string.strip():
            text_node.replaceWith(start_html + text_node.string + end_html)
    return unicode(soup)
    

#utilities    
def get_text_nodes(soup):
    return soup(text=lambda text:not isinstance(text, Comment))

#WARNING behavior changed also for mardown. but really shouldn't hurt 20100212
#it is text as received from textarea
def on_content_receive(txt, format) :
    #because textarea content arent packaged the same way on windows IE and linux FF, dhouldn't't hurt to clean it for any format
    return strip_cr(txt)