Enable Markdown rendering support for user notes and entry content

This commit is contained in:
Danielle McLean 2017-10-25 13:25:58 +11:00
parent 60cd6c911b
commit e88b631cdb
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
7 changed files with 45 additions and 5 deletions

View file

@ -21,6 +21,7 @@ django-otp = "*"
qrcode = "*" qrcode = "*"
django-otp-agents = "*" django-otp-agents = "*"
python-slugify = "*" python-slugify = "*"
django-markdown-deux = "*"
[dev-packages] [dev-packages]

14
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "a6c119918001f41c9b233d8cf9606c9acd10c6dcc13ed248f88511b198d9e929" "sha256": "c32114b4f91b4ef6f4023a180c8db8c0567a6f9206da1af2136af17dd6026b93"
}, },
"host-environment-markers": { "host-environment-markers": {
"implementation_name": "cpython", "implementation_name": "cpython",
@ -80,6 +80,12 @@
], ],
"version": "==0.0.7" "version": "==0.0.7"
}, },
"django-markdown-deux": {
"hashes": [
"sha256:5b4a3cd9454af5b4cec0e19151b41d98d09400ddae0688afb81dbf62a4edafff"
],
"version": "==1.0.5"
},
"django-meta": { "django-meta": {
"hashes": [ "hashes": [
"sha256:2a5b8d95099f69fb9736630c4fbf4fcc2972a1fcd9c708a5bb72dde22e84d8dd", "sha256:2a5b8d95099f69fb9736630c4fbf4fcc2972a1fcd9c708a5bb72dde22e84d8dd",
@ -147,6 +153,12 @@
], ],
"version": "==4.1.0" "version": "==4.1.0"
}, },
"markdown2": {
"hashes": [
"sha256:264731e7625402227ff6fb01f2d814882da7705432659a18a419c508e8bfccb1"
],
"version": "==2.3.4"
},
"olefile": { "olefile": {
"hashes": [ "hashes": [
"sha256:61f2ca0cd0aa77279eb943c07f607438edf374096b66332fae1ee64a6f0f73ad" "sha256:61f2ca0cd0aa77279eb943c07f607438edf374096b66332fae1ee64a6f0f73ad"

View file

@ -10,6 +10,8 @@ ol.entries
margin-bottom 0 margin-bottom 0
.card.h-entry .card.h-entry
.e-content > :last-child
margin-bottom 0
.card-footer .card-footer
display flex display flex
justify-content space-evenly justify-content space-evenly

View file

@ -1,7 +1,7 @@
{% load humanize %}<article class="card h-entry"> {% load humanize markdown_deux_tags %}<article class="card h-entry">
<div class="card-body"> <div class="card-body">
{% if entry.name %}<h4 class="card-title p-name">{{ entry.name }}</h4>{% endif %} {% if entry.name %}<h4 class="card-title p-name">{{ entry.name }}</h4>{% endif %}
<div class="e-content{% if not entry.name %} p-name{% endif %}">{{ entry.content }}</div> <div class="e-content{% if not entry.name %} p-name{% endif %}">{{ entry.content | markdown }}</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<a class="p-author h-card" href="{{ entry.author.url }}"> <a class="p-author h-card" href="{{ entry.author.url }}">

View file

@ -8,6 +8,8 @@ main
align-items center align-items center
aside.author aside.author
margin-bottom 1rem margin-bottom 1rem
.p-note > :last-child
margin-bottom 0
@media (min-width $md) @media (min-width $md)
flex-direction row-reverse flex-direction row-reverse
align-items unset align-items unset

View file

@ -1,5 +1,5 @@
{% extends 'lemoncurry/layout.html' %} {% extends 'lemoncurry/layout.html' %}
{% load static %} {% load markdown_deux_tags static %}
{% block styles %} {% block styles %}
<link rel="stylesheet" type="text/stylus" href="{% static 'home/css/index.styl' %}" /> <link rel="stylesheet" type="text/stylus" href="{% static 'home/css/index.styl' %}" />
<link rel="stylesheet" type="text/stylus" href="{% static 'entries/css/h-entry.styl' %}" /> <link rel="stylesheet" type="text/stylus" href="{% static 'entries/css/h-entry.styl' %}" />
@ -21,7 +21,7 @@
</a> </a>
</h6> </h6>
{% endfor %} {% endfor %}
{% if user.note %}<p class="card-text p-note">{{ user.note }}</p>{% endif %} {% if user.note %}<div class="p-note">{{ user.note | markdown:'trusted' }}</div>{% endif %}
</div> </div>
<div class="card-footer"> <div class="card-footer">

View file

@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/1.11/ref/settings/
import os import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -71,6 +72,7 @@ INSTALLED_APPS = [
'django_otp', 'django_otp',
'django_otp.plugins.otp_totp', 'django_otp.plugins.otp_totp',
'favicon', 'favicon',
'markdown_deux',
'meta', 'meta',
'lemoncurry', 'lemoncurry',
@ -205,6 +207,27 @@ AGENT_COOKIE_SECURE = True
# https://django-otp-official.readthedocs.io/en/latest/overview.html # https://django-otp-official.readthedocs.io/en/latest/overview.html
OTP_TOTP_ISSUER = LEMONCURRY_SITE_NAME OTP_TOTP_ISSUER = LEMONCURRY_SITE_NAME
# django-markdown-deux
# https://github.com/trentm/django-markdown-deux
def copy_update(source_dict, **kwargs):
copy = source_dict.copy()
copy.update(**kwargs)
return copy
MARKDOWN_DEUX_DEFAULT_STYLE = {
"extras": {
"code-friendly": None,
},
"safe_mode": "escape",
}
MARKDOWN_DEUX_STYLES = {
'default': MARKDOWN_DEUX_DEFAULT_STYLE,
'trusted': copy_update(MARKDOWN_DEUX_DEFAULT_STYLE, safe_mode=False),
}
# django-meta # django-meta
# https://django-meta.readthedocs.io/en/latest/settings.html # https://django-meta.readthedocs.io/en/latest/settings.html
META_SITE_PROTOCOL = 'https' META_SITE_PROTOCOL = 'https'