summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/html.py3
-rw-r--r--core/ld.py17
2 files changed, 19 insertions, 1 deletions
diff --git a/core/html.py b/core/html.py
index fd41a50..5045b16 100644
--- a/core/html.py
+++ b/core/html.py
@@ -20,12 +20,13 @@ def sanitize_post(post_html: str) -> str:
Only allows a, br, p and span tags, and class attributes.
"""
cleaner = bleach.Cleaner(
- tags=["a", "br", "p", "span"],
+ tags=["br", "p"],
attributes={ # type:ignore
"a": allow_a,
"p": ["class"],
"span": ["class"],
},
filters=[LinkifyFilter],
+ strip=True,
)
return mark_safe(cleaner.clean(post_html))
diff --git a/core/ld.py b/core/ld.py
index 6692dab..59b867c 100644
--- a/core/ld.py
+++ b/core/ld.py
@@ -1,4 +1,5 @@
import datetime
+import os
import urllib.parse as urllib_parse
from typing import Dict, List, Optional, Union
@@ -436,3 +437,19 @@ def parse_ld_date(value: Optional[str]) -> Optional[datetime.datetime]:
return datetime.datetime.strptime(value, DATETIME_FORMAT).replace(
tzinfo=datetime.timezone.utc
)
+
+
+def media_type_from_filename(filename):
+ _, extension = os.path.splitext(filename)
+ if extension == ".png":
+ return "image/png"
+ elif extension in [".jpg", ".jpeg"]:
+ return "image/png"
+ elif extension == ".gif":
+ return "image/gif"
+ elif extension == ".apng":
+ return "image/apng"
+ elif extension == ".webp":
+ return "image/webp"
+ else:
+ return "application/octet-stream"