Skip to content

Commit

Permalink
bluesky.from_as1: facets: handle tag displayName with @/# prefix char
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Apr 5, 2024
1 parent e30f689 commit c4377fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion granary/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def from_as1(obj, out_type=None, blobs=None, client=None):
except (KeyError, ValueError, IndexError, TypeError):
pass

name = tag.get('displayName')
name = tag.get('displayName', '').strip().lstrip('@#')
if type == 'hashtag':
facet['features'] = [{
'$type': 'app.bsky.richtext.facet#tag',
Expand Down
6 changes: 6 additions & 0 deletions granary/tests/test_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ def test_from_as1_tag_mention_html_content_guess_index(self):
'content': '<p>foo <a href="https://bsky.app/...">@you.com</a> bar</p>',
}))

def test_from_as1_tag_mention_at_char_html_content_guess_index(self):
note = copy.deepcopy(NOTE_AS_TAG_MENTION)
note['content'] = '<p>foo <a href="https://bsky.app/...">@you.com</a> bar</p>'
note['tags'][0]['displayName'] = '@you.com'
self.assert_equals(POST_BSKY_FACET_MENTION, from_as1(note))

def test_from_as1_drop_tag_with_start_past_content_length(self):
note = copy.deepcopy(NOTE_AS_TAG_HASHTAG)
note['tags'][0]['startIndex'] = len(note['content']) + 2
Expand Down

0 comments on commit c4377fd

Please sign in to comment.