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 untrusted user: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
7 changed files with 45 additions and 5 deletions

View file

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

14
Pipfile.lock generated
View file

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

View file

@ -10,6 +10,8 @@ ol.entries
margin-bottom 0
.card.h-entry
.e-content > :last-child
margin-bottom 0
.card-footer
display flex
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">
{% 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 class="card-footer">
<a class="p-author h-card" href="{{ entry.author.url }}">

View file

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

View file

@ -1,5 +1,5 @@
{% extends 'lemoncurry/layout.html' %}
{% load static %}
{% load markdown_deux_tags static %}
{% block styles %}
<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' %}" />
@ -21,7 +21,7 @@
</a>
</h6>
{% 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 class="card-footer">

View file

@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/1.11/ref/settings/
import os
# 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__))))
@ -71,6 +72,7 @@ INSTALLED_APPS = [
'django_otp',
'django_otp.plugins.otp_totp',
'favicon',
'markdown_deux',
'meta',
'lemoncurry',
@ -205,6 +207,27 @@ AGENT_COOKIE_SECURE = True
# https://django-otp-official.readthedocs.io/en/latest/overview.html
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
# https://django-meta.readthedocs.io/en/latest/settings.html
META_SITE_PROTOCOL = 'https'