Skip to content

Commit

Permalink
Render event descriptions as markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
autoantwort committed Oct 4, 2024
1 parent 482d796 commit 2522aaa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main/templates/main/event_big_card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load imagekit %}
{% load markdown_filter %}
<div class="row mb-5 mt-4">
<div class="col-12 col-sm-6">
<a href="{{ event.url_path }}">
Expand All @@ -19,7 +20,7 @@ <h6 class="text-secondary mb-0 mt-3 mt-sm-0"> {{ event.start_date }}
<h2> {{ event.name }}</h2>
{% if event.description %}
<div class="event-description">
{{ event.description|linebreaks }}
{{ event.description | markdown }}
</div>
{% endif %}
<div class="position-relative mt-auto left-0 bottom-0">
Expand Down
Empty file added main/templatetags/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions main/templatetags/markdown_filter.py
Original file line number Diff line number Diff line change
@@ -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"), )
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions studibars/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
},
]
Expand Down

0 comments on commit 2522aaa

Please sign in to comment.