From 02d7169314356fa56ad8958efe54808e77d1c516 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 14 Aug 2020 16:15:40 +0200 Subject: [PATCH] Fix tags display --- README.md | 1 - articles/models.py | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8cb9ba8..8a9122b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ Simple blog management system. ## Todo -1. Implement tags (don't render them as titles) 2. Add pagination links 3. Add some more style 4. Find a nice way to display metadata (author, dates, etc) diff --git a/articles/models.py b/articles/models.py index 4f55131..7154c03 100644 --- a/articles/models.py +++ b/articles/models.py @@ -1,3 +1,5 @@ +import re + import markdown from django.contrib.auth.models import AbstractUser from django.db import models @@ -26,10 +28,11 @@ class Article(models.Model): ordering = ["-published_at"] def get_abstract(self): - md = markdown.Markdown(extensions=["extra"]) - html = md.convert(self.content) + html = self.get_formatted_content() return html.split("")[0] def get_formatted_content(self): md = markdown.Markdown(extensions=["extra"]) - return md.convert(self.content) + content = self.content + content = re.sub(r"(\s)#(\w+)", r"\1\#\2", content) + return md.convert(content)