comparison src/browser/sat_browser/html_tools.py @ 504:f030491cff75

browser side (XMLUI): fixed bad use of text instead of XHTML in dialogs
author Goffi <goffi@goffi.org>
date Wed, 20 Aug 2014 20:59:13 +0200
parents 97c72fe4a5f2
children e876f493dccc
comparison
equal deleted inserted replaced
503:88ece2a00c63 504:f030491cff75
27 27
28 def html_sanitize(html): 28 def html_sanitize(html):
29 """Naive sanitization of HTML""" 29 """Naive sanitization of HTML"""
30 return html.replace('<', '&lt;').replace('>', '&gt;') 30 return html.replace('<', '&lt;').replace('>', '&gt;')
31 31
32
33 def html_strip(html): 32 def html_strip(html):
34 """Strip leading/trailing white spaces, HTML line breaks and &nbsp; sequences.""" 33 """Strip leading/trailing white spaces, HTML line breaks and &nbsp; sequences."""
35 cleaned = re.sub(r"^(<br/?>|&nbsp;|\s)+", "", html) 34 cleaned = re.sub(r"^(<br/?>|&nbsp;|\s)+", "", html)
36 cleaned = re.sub(r"(<br/?>|&nbsp;|\s)+$", "", cleaned) 35 cleaned = re.sub(r"(<br/?>|&nbsp;|\s)+$", "", cleaned)
37 return cleaned 36 return cleaned
38 37
39
40 def inlineRoot(xhtml): 38 def inlineRoot(xhtml):
41 """ make root element inline """ 39 """ make root element inline """
42 doc = dom.parseString(xhtml) 40 doc = dom.parseString(xhtml)
43 return xmltools.inlineRoot(doc) 41 return xmltools.inlineRoot(doc)
44 42
45
46 def convertNewLinesToXHTML(text): 43 def convertNewLinesToXHTML(text):
47 return text.replace('\n', '<br/>') 44 return text.replace('\n', '<br/>')
45
46 def XHTML2Text(xhtml):
47 """Helper method to apply both html_sanitize and convertNewLinesToXHTML"""
48 return convertNewLinesToXHTML(html_sanitize(xhtml))