mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Merge pull request #2398 from bookwyrm-social/html-in-activitypub
Render markdown to html when using activitypub
This commit is contained in:
commit
bb5564461c
3 changed files with 17 additions and 13 deletions
|
@ -13,6 +13,7 @@ from django.forms import ClearableFileInput, ImageField as DjangoImageField
|
|||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.encoding import filepath_to_uri
|
||||
from markdown import markdown
|
||||
|
||||
from bookwyrm import activitypub
|
||||
from bookwyrm.connectors import get_image
|
||||
|
@ -499,6 +500,9 @@ class HtmlField(ActivitypubFieldMixin, models.TextField):
|
|||
return None
|
||||
return clean(value)
|
||||
|
||||
def field_to_activity(self, value):
|
||||
return markdown(value) if value else value
|
||||
|
||||
|
||||
class ArrayField(ActivitypubFieldMixin, DjangoArrayField):
|
||||
"""activitypub-aware array field"""
|
||||
|
|
|
@ -383,16 +383,16 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertEqual(page_1.partOf, "http://fish.com/")
|
||||
self.assertEqual(page_1.id, "http://fish.com/?page=1")
|
||||
self.assertEqual(page_1.next, "http://fish.com/?page=2")
|
||||
self.assertEqual(page_1.orderedItems[0]["content"], "test status 29")
|
||||
self.assertEqual(page_1.orderedItems[1]["content"], "test status 28")
|
||||
self.assertEqual(page_1.orderedItems[0]["content"], "<p>test status 29</p>")
|
||||
self.assertEqual(page_1.orderedItems[1]["content"], "<p>test status 28</p>")
|
||||
|
||||
page_2 = to_ordered_collection_page(
|
||||
models.Status.objects.all(), "http://fish.com/", page=2
|
||||
)
|
||||
self.assertEqual(page_2.partOf, "http://fish.com/")
|
||||
self.assertEqual(page_2.id, "http://fish.com/?page=2")
|
||||
self.assertEqual(page_2.orderedItems[0]["content"], "test status 14")
|
||||
self.assertEqual(page_2.orderedItems[-1]["content"], "test status 0")
|
||||
self.assertEqual(page_2.orderedItems[0]["content"], "<p>test status 14</p>")
|
||||
self.assertEqual(page_2.orderedItems[-1]["content"], "<p>test status 0</p>")
|
||||
|
||||
def test_to_ordered_collection(self, *_):
|
||||
"""convert a queryset into an ordered collection object"""
|
||||
|
@ -420,8 +420,8 @@ class ActivitypubMixins(TestCase):
|
|||
)
|
||||
self.assertEqual(page_2.partOf, "http://fish.com/")
|
||||
self.assertEqual(page_2.id, "http://fish.com/?page=2")
|
||||
self.assertEqual(page_2.orderedItems[0]["content"], "test status 14")
|
||||
self.assertEqual(page_2.orderedItems[-1]["content"], "test status 0")
|
||||
self.assertEqual(page_2.orderedItems[0]["content"], "<p>test status 14</p>")
|
||||
self.assertEqual(page_2.orderedItems[-1]["content"], "<p>test status 0</p>")
|
||||
|
||||
def test_broadcast_task(self, *_):
|
||||
"""Should be calling asyncio"""
|
||||
|
|
|
@ -132,7 +132,7 @@ class Status(TestCase):
|
|||
activity = status.to_activity()
|
||||
self.assertEqual(activity["id"], status.remote_id)
|
||||
self.assertEqual(activity["type"], "Note")
|
||||
self.assertEqual(activity["content"], "test content")
|
||||
self.assertEqual(activity["content"], "<p>test content</p>")
|
||||
self.assertEqual(activity["sensitive"], False)
|
||||
|
||||
def test_status_to_activity_tombstone(self, *_):
|
||||
|
@ -156,7 +156,7 @@ class Status(TestCase):
|
|||
activity = status.to_activity(pure=True)
|
||||
self.assertEqual(activity["id"], status.remote_id)
|
||||
self.assertEqual(activity["type"], "Note")
|
||||
self.assertEqual(activity["content"], "test content")
|
||||
self.assertEqual(activity["content"], "<p>test content</p>")
|
||||
self.assertEqual(activity["sensitive"], False)
|
||||
self.assertEqual(activity["attachment"], [])
|
||||
|
||||
|
@ -170,7 +170,7 @@ class Status(TestCase):
|
|||
activity = status.to_activity()
|
||||
self.assertEqual(activity["id"], status.remote_id)
|
||||
self.assertEqual(activity["type"], "GeneratedNote")
|
||||
self.assertEqual(activity["content"], "test content")
|
||||
self.assertEqual(activity["content"], "<p>test content</p>")
|
||||
self.assertEqual(activity["sensitive"], False)
|
||||
self.assertEqual(len(activity["tag"]), 2)
|
||||
|
||||
|
@ -208,7 +208,7 @@ class Status(TestCase):
|
|||
activity = status.to_activity()
|
||||
self.assertEqual(activity["id"], status.remote_id)
|
||||
self.assertEqual(activity["type"], "Comment")
|
||||
self.assertEqual(activity["content"], "test content")
|
||||
self.assertEqual(activity["content"], "<p>test content</p>")
|
||||
self.assertEqual(activity["inReplyToBook"], self.book.remote_id)
|
||||
|
||||
def test_comment_to_pure_activity(self, *_):
|
||||
|
@ -243,8 +243,8 @@ class Status(TestCase):
|
|||
activity = status.to_activity()
|
||||
self.assertEqual(activity["id"], status.remote_id)
|
||||
self.assertEqual(activity["type"], "Quotation")
|
||||
self.assertEqual(activity["quote"], "a sickening sense")
|
||||
self.assertEqual(activity["content"], "test content")
|
||||
self.assertEqual(activity["quote"], "<p>a sickening sense</p>")
|
||||
self.assertEqual(activity["content"], "<p>test content</p>")
|
||||
self.assertEqual(activity["inReplyToBook"], self.book.remote_id)
|
||||
|
||||
def test_quotation_to_pure_activity(self, *_):
|
||||
|
@ -285,7 +285,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["type"], "Review")
|
||||
self.assertEqual(activity["rating"], 3)
|
||||
self.assertEqual(activity["name"], "Review name")
|
||||
self.assertEqual(activity["content"], "test content")
|
||||
self.assertEqual(activity["content"], "<p>test content</p>")
|
||||
self.assertEqual(activity["inReplyToBook"], self.book.remote_id)
|
||||
|
||||
def test_review_to_pure_activity(self, *_):
|
||||
|
|
Loading…
Reference in a new issue