[IMP] tools: mail: improved html_email_clean
- 'read more' links are now in the last container, not after, allowing to have read more links embedded inside shortened paragraphs - added expand_options dict allowing to customize the read more bzr revid: tde@openerp.com-20130923112939-0ab4idlzqpug00xz
This commit is contained in:
parent
6188a2af5b
commit
be966b02c7
|
@ -99,7 +99,7 @@ def html_sanitize(src, silent=True):
|
|||
# HTML Cleaner
|
||||
#----------------------------------------------------------
|
||||
|
||||
def html_email_clean(html, remove=False, shorten=False, max_length=300):
|
||||
def html_email_clean(html, remove=False, shorten=False, max_length=300, expand_options=None):
|
||||
""" html_email_clean: clean the html by doing the following steps:
|
||||
|
||||
- try to strip email quotes, by removing blockquotes or having some client-
|
||||
|
@ -170,6 +170,9 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300):
|
|||
iteration += 1
|
||||
new_node = _insert_new_node(node, -1, new_node_tag, text[idx:] + (cur_node.tail or ''), None, {})
|
||||
|
||||
if expand_options is None:
|
||||
expand_options = {}
|
||||
|
||||
if not html or not isinstance(html, basestring):
|
||||
return html
|
||||
html = ustr(html)
|
||||
|
@ -252,14 +255,26 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300):
|
|||
stop_idx = len(outertext)
|
||||
node.text = innertext + outertext[0:stop_idx]
|
||||
# create <span> ... <a href="#">read more</a></span> node
|
||||
read_more_node = _create_node('span', ' ... ', None, {'class': 'oe_mail_expand'})
|
||||
read_more_link_node = _create_node('a', 'read more', None, {'href': '#', 'class': 'oe_mail_expand'})
|
||||
read_more_node = _create_node(
|
||||
'span',
|
||||
' ... ',
|
||||
None,
|
||||
{'class': expand_options.get('oe_expand_span_class', 'oe_mail_expand')}
|
||||
)
|
||||
read_more_link_node = _create_node(
|
||||
'a',
|
||||
'read more',
|
||||
None,
|
||||
{
|
||||
'href': expand_options.get('oe_expand_href', '#'),
|
||||
'class': expand_options.get('oe_expand_a_class', 'oe_mail_expand'),
|
||||
}
|
||||
)
|
||||
read_more_node.append(read_more_link_node)
|
||||
# create outertext node
|
||||
new_node = _create_node('span', outertext[stop_idx:])
|
||||
# add newly created nodes in dom
|
||||
node.addnext(new_node)
|
||||
node.addnext(read_more_node)
|
||||
node.append(read_more_node)
|
||||
# tag node
|
||||
new_node.set('in_overlength', '1')
|
||||
|
||||
|
|
Loading…
Reference in New Issue