diff --git a/main/templates/main/event_big_card.html b/main/templates/main/event_big_card.html index b5f7648..43f209a 100644 --- a/main/templates/main/event_big_card.html +++ b/main/templates/main/event_big_card.html @@ -1,4 +1,5 @@ {% load imagekit %} +{% load markdown_filter %}
@@ -19,7 +20,7 @@
{{ event.start_date }}

{{ event.name }}

{% if event.description %}
- {{ event.description|linebreaks }} + {{ event.description | markdown }}
{% endif %}
diff --git a/main/templatetags/__init__.py b/main/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/templatetags/markdown_filter.py b/main/templatetags/markdown_filter.py new file mode 100644 index 0000000..bb5a1ea --- /dev/null +++ b/main/templatetags/markdown_filter.py @@ -0,0 +1,13 @@ +from django import template +from django.template.defaultfilters import stringfilter +from django.utils.safestring import mark_safe +from markdown import markdown + +register = template.Library() + + +@register.filter(name='markdown') +@stringfilter +def markdown_filter(value: str): + # always render new lines as new lines, even without two ending spaces + return mark_safe(markdown(value).replace("\r\n", " \r\n"), ) diff --git a/requirements.txt b/requirements.txt index 4e93ff2..41b56eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ git+https://github.com/math-a3k/django-bootstrap-v5.git@9d9f01988f0554028c0fd276 channels[daphne]>=4.1.0 channels-redis asgiref~=3.8.1 +markdown diff --git a/studibars/settings.py b/studibars/settings.py index e48fefe..2f6ddf5 100644 --- a/studibars/settings.py +++ b/studibars/settings.py @@ -75,6 +75,10 @@ "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", ], + 'libraries': { + 'staticfiles': 'django.templatetags.static', + 'markdown_filter': 'main.templatetags.markdown_filter', + }, }, }, ]