comparison libervia/web/server/html_tools.py @ 1518:eb00d593801d

refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 16:49:28 +0200
parents libervia/server/html_tools.py@106bae41f5c8
children
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3
4 # Libervia: a Salut à Toi frontend
5 # Copyright (C) 2011-2021 Jérôme Poisson <goffi@goffi.org>
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21 def sanitize_html(text):
22 """Sanitize HTML by escaping everything"""
23 # this code comes from official python wiki: http://wiki.python.org/moin/EscapingHtml
24 html_escape_table = {
25 "&": "&amp;",
26 '"': "&quot;",
27 "'": "&apos;",
28 ">": "&gt;",
29 "<": "&lt;",
30 }
31
32 return "".join(html_escape_table.get(c, c) for c in text)
33
34
35 def convert_new_lines_to_xhtml(text):
36 return text.replace("\n", "<br/>")