Mercurial > libervia-web
annotate browser_side/html_tools.py @ 370:30d03d9f07e4
browser_side: refactorization of the file tools.py:
- tools.py renamed to html_tools.py
- method setPresenceStyle moved to contact.py
- classes DragLabel and LiberviaDragWidget moved to base_widget.py
- class FilterFileUpload moved to file_tools.py
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 23 Feb 2014 17:01:03 +0100 |
parents | browser_side/tools.py@187126b63170 |
children | 41b8b96f2248 |
rev | line source |
---|---|
31
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
340 | 5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org> |
31
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
10 # (at your option) any later version. |
31
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
15 # GNU Affero General Public License for more details. |
31
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
31
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
246
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
20 from nativedom import NativeDOM |
332
6abd099c7007
browser side: sat_frontends.tools.xml is now called xmltools
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
21 from sat_frontends.tools import xmltools |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
22 import re |
246
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
23 |
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
24 dom = NativeDOM() |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
25 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
26 |
31
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 def html_sanitize(html): |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 """Naive sanitization of HTML""" |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
29 return html.replace('<', '<').replace('>', '>') |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
30 |
217
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
31 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
32 def html_strip(html): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
33 """Strip leading/trailing white spaces, HTML line breaks and sequences.""" |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
34 cleaned = re.sub(r"^(<br/?>| |\s)+", "", html) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
35 cleaned = re.sub(r"(<br/?>| |\s)+$", "", cleaned) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
36 return cleaned |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
37 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
38 |
246
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
39 def inlineRoot(xhtml): |
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
40 """ make root element inline """ |
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
41 doc = dom.parseString(xhtml) |
332
6abd099c7007
browser side: sat_frontends.tools.xml is now called xmltools
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
42 return xmltools.inlineRoot(doc) |