|
0
|
1 |
""" |
|
|
2 |
Package to manipulage html chunks |
|
|
3 |
""" |
|
|
4 |
|
|
175
|
5 |
from string_utils import strip_cr |
|
0
|
6 |
from BeautifulSoup import BeautifulSoup, Comment |
|
|
7 |
|
|
|
8 |
def surrond_text_node(html_chunk, start_html, end_html): |
|
|
9 |
""" |
|
|
10 |
Surround text nodes in html_chunk |
|
|
11 |
""" |
|
|
12 |
soup = BeautifulSoup(html_chunk) |
|
|
13 |
text_nodes = get_text_nodes(soup) |
|
|
14 |
for text_node in text_nodes: |
|
|
15 |
if text_node.string.strip(): |
|
|
16 |
text_node.replaceWith(start_html + text_node.string + end_html) |
|
|
17 |
return unicode(soup) |
|
|
18 |
|
|
|
19 |
|
|
175
|
20 |
#utilities |
|
0
|
21 |
def get_text_nodes(soup): |
|
|
22 |
return soup(text=lambda text:not isinstance(text, Comment)) |
|
175
|
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 |
|