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
+1
View File
@@ -72,6 +72,7 @@ def newentry():
return render_template('entry/create.html')
content = str(request.form["content"])
content = content.strip()
content = content[:1000]
fileattached = False
+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
+6 -2
View File
@@ -51,7 +51,8 @@ hr {
justify-content: center;
align-items: center;
gap: 10pt; }
#contentnotice h1, #contentnotice h3 {
#contentnotice h1,
#contentnotice h3 {
margin: 6pt; }
#contentnotice div {
width: 100%;
@@ -64,7 +65,10 @@ hr {
.entry .content {
margin: 10pt;
font-size: 14pt; }
font-size: 14pt;
word-wrap: break-word;
max-height: 500px;
overflow: hidden; }
.entry img {
max-width: 100%; }
+6 -1
View File
@@ -66,7 +66,8 @@ hr {
align-items: center;
gap: 10pt;
h1, h3 {
h1,
h3 {
margin: 6pt;
}
@@ -86,6 +87,10 @@ hr {
.content {
margin: 10pt;
font-size: 14pt;
word-wrap: break-word;
max-height: 500px;
overflow: hidden;
}
img {
+3 -1
View File
@@ -2,9 +2,11 @@
<div class="entry">
<div class="meta">{{ p[6] }} - {{ p[3] | timestamp }}<br /></div>
{% if p[4] != '' %}
<div class="content">
<p>{{ p[4] }}</p>
<p>{{ p[4] | content | safe}}</p>
</div>
{% endif %}
{% if p[5] != 'none' %}
<img src="/{{ p[5] }}" />
{% endif %}