Render content with commonmark, save markdown to source

merge-requests/156/head
Jason Robinson 2019-08-18 04:25:13 +03:00
rodzic 441a65e18a
commit 564f917f7a
4 zmienionych plików z 23 dodań i 5 usunięć

Wyświetl plik

@ -3,6 +3,7 @@ import uuid
from typing import Dict
import attr
from commonmark import commonmark
from federation.entities.activitypub.constants import (
CONTEXTS_DEFAULT, CONTEXT_MANUALLY_APPROVES_FOLLOWERS, CONTEXT_SENSITIVE, CONTEXT_HASHTAG,
@ -50,13 +51,17 @@ class ActivitypubNoteMixin(AttachImagesMixin, CleanContentMixin, ActivitypubEnti
"id": self.id,
"type": self._type,
"attributedTo": self.actor_id,
"content": self.raw_content, # TODO render to html, add source markdown
"content": commonmark(self.raw_content).strip(),
"published": self.created_at.isoformat(),
"inReplyTo": None,
"sensitive": True if "nsfw" in self.tags else False,
"summary": None, # TODO Short text? First sentence? First line?
"tag": [], # TODO add tags
"url": self.url,
'source': {
'content': self.raw_content,
'mediaType': 'text/markdown',
},
},
"published": self.created_at.isoformat(),
}

Wyświetl plik

@ -53,13 +53,17 @@ class TestEntitiesConvertToAS2:
'id': 'http://127.0.0.1:8000/post/123456/',
'type': 'Note',
'attributedTo': 'http://127.0.0.1:8000/profile/123456/',
'content': 'raw_content',
'content': '<p>raw_content</p>',
'published': '2019-04-27T00:00:00',
'inReplyTo': 'http://127.0.0.1:8000/post/012345/',
'sensitive': False,
'summary': None,
'tag': [],
'url': '',
'source': {
'content': 'raw_content',
'mediaType': 'text/markdown',
},
},
'published': '2019-04-27T00:00:00',
}
@ -106,13 +110,17 @@ class TestEntitiesConvertToAS2:
'id': 'http://127.0.0.1:8000/post/123456/',
'type': 'Note',
'attributedTo': 'http://127.0.0.1:8000/profile/123456/',
'content': 'raw_content',
'content': '<h1>raw_content</h1>',
'published': '2019-04-27T00:00:00',
'inReplyTo': None,
'sensitive': False,
'summary': None,
'tag': [],
'url': '',
'source': {
'content': '# raw_content',
'mediaType': 'text/markdown',
},
},
'published': '2019-04-27T00:00:00',
}
@ -134,7 +142,7 @@ class TestEntitiesConvertToAS2:
'id': 'http://127.0.0.1:8000/post/123456/',
'type': 'Note',
'attributedTo': 'http://127.0.0.1:8000/profile/123456/',
'content': 'raw_content',
'content': '<p>raw_content</p>',
'published': '2019-04-27T00:00:00',
'inReplyTo': None,
'sensitive': False,
@ -155,6 +163,10 @@ class TestEntitiesConvertToAS2:
'url': 'barfoo',
},
],
'source': {
'content': 'raw_content',
'mediaType': 'text/markdown',
},
},
'published': '2019-04-27T00:00:00',
}

Wyświetl plik

@ -61,7 +61,7 @@ def activitypubaccept(activitypubfollow):
def activitypubpost():
with freeze_time("2019-04-27"):
return ActivitypubPost(
raw_content="raw_content",
raw_content="# raw_content",
public=True,
provider_display_name="Socialhome",
id=f"http://127.0.0.1:8000/post/123456/",

Wyświetl plik

@ -28,6 +28,7 @@ setup(
license="BSD 3-clause",
install_requires=[
"attrs",
"commonmark",
"cryptography",
"cssselect>=0.9.2",
"dirty-validators>=0.3.0",