Skip to content

Commit

Permalink
Render description markdown
Browse files Browse the repository at this point in the history
The description for global scripts are written in markdown. This commit makes Django render the markdown, instead of showing the raw markdown code.
  • Loading branch information
NeutraChikara committed Nov 26, 2024
1 parent 6343396 commit 474a980
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion admin_site/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ psycopg==3.1.18 # Used in the example docker-compose.yml
python-dateutil==2.8.2 # Required by django-xmlrpc
requests==2.31.0
whitenoise==6.6.0 # If you don't have a web server in front to serve static files
PyYAML==6.0.2
PyYAML==6.0.2
markdown==3.7
9 changes: 9 additions & 0 deletions admin_site/system/templatetags/markdown_extras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import markdown
from django import template
from django.utils.safestring import mark_safe

register = template.Library()

@register.filter(name='markdown')
def markdown_format(text):
return mark_safe(markdown.markdown(text))
9 changes: 7 additions & 2 deletions admin_site/templates/system/scripts/form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load crispy_forms_tags %}
{% load markdown_extras %}

{% load i18n %}

Expand All @@ -24,8 +25,12 @@
{% endif %}

<fieldset>
{{ form.name|as_crispy_field }}
{{ form.description|as_crispy_field }}
{% if global_script %}
{{ form.description.value|markdown }}
{% else %}
{{ form.name|as_crispy_field }}
{{ form.description|as_crispy_field }}
{% endif %}

<input
type="hidden"
Expand Down
1 change: 0 additions & 1 deletion admin_site/templates/system/scripts/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ <h2 class="divideheader">

<div class="clearfix"></div>

<!-- TODO-script render markdown instead of showing a form -->
{% include 'system/scripts/form.html' with show_code_preview=1 global_script=script.is_global %}

<fieldset class="gray-box mt-0 pt-0" style="border-radius: 0 0 .33rem .33rem;">
Expand Down

0 comments on commit 474a980

Please sign in to comment.