Mercurial > libervia-web
comparison src/browser/sat_browser/html_tools.py @ 848:7dafa5ee809a
browser: replace re module usage by pure javascript
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 15 Jan 2016 16:33:08 +0100 |
parents | f8a7a046ff9c |
children | fd4eae654182 |
comparison
equal
deleted
inserted
replaced
847:330db23d4a44 | 848:7dafa5ee809a |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat_frontends.tools import xmltools | 20 from sat_frontends.tools import xmltools |
21 | 21 |
22 import nativedom | 22 import nativedom |
23 import re | 23 from __pyjamas__ import JS |
24 | 24 |
25 dom = nativedom.NativeDOM() | 25 dom = nativedom.NativeDOM() |
26 | 26 |
27 | 27 |
28 def html_sanitize(html): | 28 def html_sanitize(html): |
30 return html.replace('<', '<').replace('>', '>') | 30 return html.replace('<', '<').replace('>', '>') |
31 | 31 |
32 | 32 |
33 def html_strip(html): | 33 def html_strip(html): |
34 """Strip leading/trailing white spaces, HTML line breaks and sequences.""" | 34 """Strip leading/trailing white spaces, HTML line breaks and sequences.""" |
35 cleaned = re.sub(r"^(<br/?>| |\s)+", "", html) | 35 JS("""return html.replace(/(^(<br\/?>| |\s)+)|((<br\/?>| |\s)+$)/g, "");""") |
36 cleaned = re.sub(r"(<br/?>| |\s)+$", "", cleaned) | |
37 return cleaned | |
38 | |
39 | 36 |
40 def inlineRoot(xhtml): | 37 def inlineRoot(xhtml): |
41 """ make root element inline """ | 38 """ make root element inline """ |
42 doc = dom.parseString(xhtml) | 39 doc = dom.parseString(xhtml) |
43 return xmltools.inlineRoot(doc) | 40 return xmltools.inlineRoot(doc) |