From 01c96511317ca8da64f6531d7ce30363e43b53fb Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sun, 25 Feb 2018 20:46:41 +0100 Subject: [PATCH] Add markdown support for flat pages --- Pipfile | 1 + Pipfile.lock | 13 ++++++++++--- pages/models.py | 15 +++++++++++++++ pages/templates/pages/page.html | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Pipfile b/Pipfile index a34c012..ff35b7b 100644 --- a/Pipfile +++ b/Pipfile @@ -9,6 +9,7 @@ name = "pypi" django = "*" python-decouple = "*" +markdown = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 34ae6f8..d2304f9 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "c9096173a460c37db5cae58c8f61c3371b5e1fe5d436ccc27c29091ebd06fc4f" + "sha256": "afe4d05c7a34f361ac700b159c1844aab93669730285b054bf92bbf33bd5ff60" }, "host-environment-markers": { "implementation_name": "cpython", @@ -9,9 +9,9 @@ "os_name": "posix", "platform_machine": "x86_64", "platform_python_implementation": "CPython", - "platform_release": "4.15.1-2-ARCH", + "platform_release": "4.15.4-1-ARCH", "platform_system": "Linux", - "platform_version": "#1 SMP Sun Feb 4 22:27:45 UTC 2018", + "platform_version": "#1 SMP PREEMPT Sat Feb 17 16:01:38 UTC 2018", "python_full_version": "3.6.4", "python_version": "3.6", "sys_platform": "linux" @@ -34,6 +34,13 @@ ], "version": "==2.0.2" }, + "markdown": { + "hashes": [ + "sha256:9ba587db9daee7ec761cfc656272be6aabe2ed300fece21208e4aab2e457bc8f", + "sha256:a856869c7ff079ad84a3e19cd87a64998350c2b94e9e08e44270faef33400f81" + ], + "version": "==2.6.11" + }, "python-decouple": { "hashes": [ "sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d" diff --git a/pages/models.py b/pages/models.py index 77f7c80..cbf3cd1 100644 --- a/pages/models.py +++ b/pages/models.py @@ -1,5 +1,6 @@ from django.conf import settings from django.db import models +import markdown class Page(models.Model): @@ -18,5 +19,19 @@ class PageContent(models.Model): title = models.CharField(max_length=200) content = models.TextField() + def formated_content(self): + return markdown.markdown( + self.content, + extensions=[ + 'markdown.extensions.extra', + 'markdown.extensions.admonition', + 'markdown.extensions.nl2br', + 'markdown.extensions.sane_lists', + 'markdown.extensions.smarty', + 'markdown.extensions.toc', + ], + output_format='html5', + ) + def __str__(self): return self.title diff --git a/pages/templates/pages/page.html b/pages/templates/pages/page.html index d8807a0..394cc1b 100644 --- a/pages/templates/pages/page.html +++ b/pages/templates/pages/page.html @@ -3,5 +3,5 @@ {% block title %}{{ page.title }}{% endblock %} {% block content %} -{{ page.content|safe }} +{{ page.formated_content|safe }} {% endblock %}