diff --git a/entries/models.py b/entries/models.py index 876b017..cf1e127 100644 --- a/entries/models.py +++ b/entries/models.py @@ -13,7 +13,7 @@ from model_utils.models import TimeStampedModel from users.models import Profile from . import kinds -from lemoncurry import requests +from lemoncurry import requests, utils ENTRY_KINDS = [(k.id, k.id) for k in kinds.all] @@ -98,12 +98,12 @@ class Entry(ModelMeta, TimeStampedModel): def title(self): if self.name: return self.name - return shorten(self.paragraphs[0], width=100, placeholder='…') + return shorten(utils.to_plain(self.paragraphs[0]), width=100, placeholder='…') @property def excerpt(self): try: - return self.paragraphs[0 if self.name else 1] + return utils.to_plain(self.paragraphs[0 if self.name else 1]) except IndexError: return ' ' diff --git a/lemoncurry/utils.py b/lemoncurry/utils.py index 6fc0be4..5c122b9 100644 --- a/lemoncurry/utils.py +++ b/lemoncurry/utils.py @@ -1,14 +1,18 @@ +import html import json from accept_types import get_best_match from django.conf import settings from django.http import HttpResponse, JsonResponse from django.http import HttpResponseForbidden, HttpResponseBadRequest +from django.utils.html import strip_tags from os.path import join from shorturls import default_converter as converter from shorturls.templatetags.shorturl import ShortURL from types import SimpleNamespace from urllib.parse import urlencode, urljoin +from .templatetags.markdown import markdown + cache = SimpleNamespace(package_json=None) @@ -63,3 +67,7 @@ def bad_req(message): def forbid(message): return HttpResponseForbidden(message, content_type='text/plain') + + +def to_plain(md): + return html.unescape(strip_tags(markdown(md))) diff --git a/users/models.py b/users/models.py index e49d15d..49caeff 100644 --- a/users/models.py +++ b/users/models.py @@ -4,6 +4,7 @@ from django.contrib.sites.models import Site as DjangoSite from django.utils.functional import cached_property from meta.models import ModelMeta from urllib.parse import urljoin +from lemoncurry import utils def avatar_path(instance, name): @@ -45,6 +46,10 @@ class User(ModelMeta, AbstractUser): def get_absolute_url(self): return self.url + @property + def description(self): + return utils.to_plain(self.note) + @property def avatar_url(self): return self.avatar.url @@ -81,7 +86,7 @@ class User(ModelMeta, AbstractUser): _metadata = { 'image': 'avatar_url', - 'description': 'note', + 'description': 'description', 'og_type': 'profile', 'og_profile_id': 'facebook_id', 'twitter_creator': 'twitter_username',