kopia lustrzana https://github.com/snarfed/bridgy-fed
activitypub.postprocess_as2: linkify indexed tags in content
makes Mastodon etc link them correctly to the local instance's UI in its renderingpull/1067/head
rodzic
9243e18a4f
commit
edf3b5894e
|
@ -736,6 +736,8 @@ def postprocess_as2(activity, orig_obj=None, wrap=True):
|
|||
if not name.startswith('#'):
|
||||
tag['name'] = f'#{name}'
|
||||
|
||||
as2.link_tags(obj_or_activity)
|
||||
|
||||
# language, in contentMap
|
||||
# https://github.com/snarfed/bridgy-fed/issues/681
|
||||
if content := obj_or_activity.get('content'):
|
||||
|
|
|
@ -2011,6 +2011,36 @@ class ActivityPubUtilsTest(TestCase):
|
|||
],
|
||||
}))
|
||||
|
||||
def test_postprocess_as2_plain_text_content_links_hashtags_mentions(self):
|
||||
expected = 'foo <a href="http://inst/bar">@bar</a> <a href="http://inst/baz">#baz</a>'
|
||||
self.assert_equals({
|
||||
'content': expected,
|
||||
'contentMap': {'en': expected},
|
||||
'content_is_html': True,
|
||||
'tag': [{
|
||||
'type': 'Tag',
|
||||
'href': 'http://inst/bar',
|
||||
}, {
|
||||
'type': 'Mention',
|
||||
'href': 'http://inst/baz',
|
||||
}],
|
||||
'to': [as2.PUBLIC_AUDIENCE],
|
||||
'cc': ['http://inst/baz'],
|
||||
}, postprocess_as2({
|
||||
'content': 'foo @bar #baz',
|
||||
'tag': [{
|
||||
'type': 'Tag',
|
||||
'href': 'http://inst/bar',
|
||||
'startIndex': 4,
|
||||
'length': 4,
|
||||
}, {
|
||||
'type': 'Mention',
|
||||
'href': 'http://inst/baz',
|
||||
'startIndex': 9,
|
||||
'length': 4,
|
||||
}],
|
||||
}))
|
||||
|
||||
def test_postprocess_as2_strips_link_attachment(self):
|
||||
self.assertNotIn('attachment', postprocess_as2({
|
||||
'type': 'Note',
|
||||
|
|
Ładowanie…
Reference in New Issue