From 3656a6f34c351cc2d1951469113f6aee4abf3ec0 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 30 Jan 2025 17:28:29 +0530 Subject: [PATCH] use markdown all the way --- camp/settings.py | 1 + content/models.py | 8 ++++++++ content/templates/content.html | 8 ++++++-- content/templates/events.html | 8 ++++++-- content/templates/index.html | 8 ++++++-- content/templates/opt.html | 8 ++++++-- content/templates/works.html | 8 ++++++-- content/utils.py | 5 +++++ 8 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 content/utils.py diff --git a/camp/settings.py b/camp/settings.py index ffeb8c3..3de754b 100644 --- a/camp/settings.py +++ b/camp/settings.py @@ -144,6 +144,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static') MARKDOWNX_MEDIA_PATH = 'images/markdown' MARKDOWNX_EDITOR_RESIZABLE = True +MARKDOWNX_MARKDOWNIFY_FUNCTION = 'content.utils.markdownify' MEDIA_URL = '/static/images/' MEDIA_ROOT = os.path.join(BASE_DIR, 'data/images') diff --git a/content/models.py b/content/models.py index cf79f41..c9a4942 100644 --- a/content/models.py +++ b/content/models.py @@ -138,6 +138,14 @@ class Content(models.Model): def formatted_schedule(self): return mark_safe(markdownify(self.schedule)) + @property + def formatted_opttext2(self): + return mark_safe(markdownify(self.opttext2)) + + @property + def formatted_opttext3(self): + return mark_safe(markdownify(self.opttext3)) + @property def typefilter(self): return self.type diff --git a/content/templates/content.html b/content/templates/content.html index ebe0b30..711e260 100644 --- a/content/templates/content.html +++ b/content/templates/content.html @@ -19,8 +19,12 @@ {% if content.place %}
{{content.place}}{% endif%} {% endif %} -

{{content.formatted_header|safe}}

-

{{content.formatted_body|safe}}

+

+ {{content.formatted_header}} +

+

+ {{content.formatted_body}} +

{% include "opt.html" %} {% include "links.html" %} {% include "gallery.html" with gallery=content.gallery %} diff --git a/content/templates/events.html b/content/templates/events.html index 7122d5d..b1ce0c7 100644 --- a/content/templates/events.html +++ b/content/templates/events.html @@ -8,8 +8,12 @@ {% endif %}

{{events.title}}

-

{{events.formatted_header|safe}}

-

{{events.formatted_body|safe}}

+

+ {{events.formatted_header}} +

+

+ {{events.formatted_body}} +

{% include "opt.html" with content=events %} {% include "links.html" with content=events %} {% include "gallery.html" with gallery=gallery %} diff --git a/content/templates/index.html b/content/templates/index.html index ba655f5..23ff27d 100644 --- a/content/templates/index.html +++ b/content/templates/index.html @@ -7,8 +7,12 @@

{{content.title}}

-

{{content.formatted_header}}

-

{{content.formatted_body}}

+

+ {{content.formatted_header}} +

+

+ {{content.formatted_body}} +

{% endfor %} diff --git a/content/templates/opt.html b/content/templates/opt.html index a0a4e8d..10c5a47 100644 --- a/content/templates/opt.html +++ b/content/templates/opt.html @@ -3,7 +3,9 @@ {% if content.optbtn2 %}

{{ content.optbtn2|safe }}

{% endif %} -

{{ content.opttext2|safe|linebreaks }}

+

+ {{ content.formatted_opttext2 }} +

{% endif %} {% if content.opttext3 %} @@ -11,7 +13,9 @@ {% if content.optbtn3 %}

{{ content.optbtn3|safe }}

{% endif %} -

{{ content.opttext3|safe|linebreaks }}

+

+ {{ content.formatted_opttext3 }} +

{% endif %} {% if content.schedule %} diff --git a/content/templates/works.html b/content/templates/works.html index 700463d..e2cc4f6 100644 --- a/content/templates/works.html +++ b/content/templates/works.html @@ -8,8 +8,12 @@ {% endif %}

{{works.title}}

-

{{works.formatted_header|safe}}

-

{{works.formatted_body|safe}}

+

+ {{works.formatted_header}} +

+

+ {{works.formatted_body}} +

{% include "opt.html" with content=works %} {% include "links.html" with content=projects %} {% include "gallery.html" with gallery=gallery %} diff --git a/content/utils.py b/content/utils.py new file mode 100644 index 0000000..fe5e934 --- /dev/null +++ b/content/utils.py @@ -0,0 +1,5 @@ +import markdownx.utils + +def markdownify(string): + string = markdownx.utils.markdownify(string) + return string