Added content filter for max len and URLs

This commit is contained in:
2025-12-17 22:14:30 +01:00
parent 01e6e92c78
commit 37c3c8dac8
5 changed files with 39 additions and 4 deletions
+23
View File
@@ -20,6 +20,29 @@ def timestamp_filter(value):
except:
return value
import html, re
@app.template_filter('content')
def content_filter(value):
value = value.strip()
value = html.escape(value)
# Regulärer Ausdruck, um URLs zu finden
url_pattern = re.compile(
r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
)
# Ersetze jede gefundene URL durch einen <a>-Tag
def replace_url(match):
url = match.group(0)
if not url.startswith(('http://', 'https://')):
url = 'http://' + url
return f'<a href="{url}" target="_blank">{match.group(0)}</a>'
value = url_pattern.sub(replace_url, value)
value = value.replace('\n', '<br>')
return value
import auth
import entry
import user