Allow markdown in html fields
This commit is contained in:
@ -11,6 +11,7 @@ from django.core.files.base import ContentFile
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from markdown import markdown
|
||||
from bookwyrm import activitypub
|
||||
from bookwyrm.sanitize_html import InputHtmlParser
|
||||
from bookwyrm.settings import DOMAIN
|
||||
@ -25,6 +26,7 @@ def validate_remote_id(value):
|
||||
params={'value': value},
|
||||
)
|
||||
|
||||
|
||||
def validate_username(value):
|
||||
''' make sure usernames look okay '''
|
||||
if not re.match(r'^[A-Za-z\-_\.]+$', value):
|
||||
@ -399,6 +401,16 @@ class HtmlField(ActivitypubFieldMixin, models.TextField):
|
||||
sanitizer.feed(value)
|
||||
return sanitizer.get_output()
|
||||
|
||||
def to_python(self, value):# pylint: disable=no-self-use
|
||||
''' process markdown before save '''
|
||||
if not value:
|
||||
return value
|
||||
content = markdown(value)
|
||||
# sanitize resulting html
|
||||
sanitizer = InputHtmlParser()
|
||||
sanitizer.feed(content)
|
||||
return sanitizer.get_output()
|
||||
|
||||
class ArrayField(ActivitypubFieldMixin, DjangoArrayField):
|
||||
''' activitypub-aware array field '''
|
||||
def field_to_activity(self, value):
|
||||
|
Reference in New Issue
Block a user