Added content filter for max len and URLs
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user