Skip to content

Commit

Permalink
twitter/mf2: use u-quotation-of for quote tweets, AS attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Jan 24, 2017
1 parent 43d1e32 commit 275603f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ Changelog

### 1.7 - unreleased
* Source.get_activities(): start raising ValueError on bad argument values, notably invalid Facebook and Twitter ids and Instagram search queries.
* microformats2:
* Use [experimental u-quotation-of property](https://indieweb.org/quotation#How_to_markup) for attachments, e.g. quote tweets.
* Twitter:
* Linkify @-mentions and hashtags in `preview_create()`.
* Instagram:
Expand Down
12 changes: 7 additions & 5 deletions granary/microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def object_to_json(obj, trim_nulls=True, entry_class='h-entry',
Args:
obj: dict, a decoded JSON ActivityStreams object
trim_nulls: boolean, whether to remove elements with null or empty values
entry_class: string, the mf2 class that entries should be given (e.g.
'h-cite' when parsing a reference to a foreign entry). defaults to
'h-entry'
entry_class: string or sequence, the mf2 class(es) that entries should be
given (e.g. 'h-cite' when parsing a reference to a foreign entry).
defaults to 'h-entry'
default_object_type: string, the ActivityStreams objectType to use if one
is not present. defaults to None
synthesize_content: whether to generate synthetic content if the object
Expand Down Expand Up @@ -145,7 +145,8 @@ def object_to_json(obj, trim_nulls=True, entry_class='h-entry',
ret = {
'type': (['h-card'] if obj_type == 'person'
else ['h-card', 'p-location'] if obj_type == 'place'
else [entry_class]),
else [entry_class] if isinstance(entry_class, basestring)
else list(entry_class)),
'properties': {
'uid': [obj.get('id', '')],
'name': [name],
Expand Down Expand Up @@ -173,7 +174,8 @@ def object_to_json(obj, trim_nulls=True, entry_class='h-entry',
'comment': [object_to_json(c, trim_nulls=False, entry_class='h-cite')
for c in obj.get('replies', {}).get('items', [])],
},
'children': [object_to_json(c, trim_nulls=False, entry_class='h-cite')
'children': [object_to_json(c, trim_nulls=False,
entry_class=['u-quotation-of', 'h-cite'])
for c in primary.get('attachments', [])
if c.get('objectType') in ('note', 'article')],
}
Expand Down
8 changes: 4 additions & 4 deletions granary/test/test_microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,16 @@ def test_attachments_to_children(self):
]}

self.assert_equals([{
'type': ['h-cite'],
'type': ['u-quotation-of', 'h-cite'],
'properties': {'url': ['http://p'], 'name': ['p']},
}, {
'type': ['h-cite'],
'type': ['u-quotation-of', 'h-cite'],
'properties': {'url': ['http://a']},
}], microformats2.object_to_json(obj)['children'])

html = microformats2.object_to_html(obj)
self.assert_multiline_in("""\
<article class="h-cite">
<article class="u-quotation-of h-cite">
<span class="p-uid"></span>
<a class="p-name u-url" href="http://p">p</a>
Expand All @@ -369,7 +369,7 @@ def test_attachments_to_children(self):
</article>
<article class="h-cite">
<article class="u-quotation-of h-cite">
<span class="p-uid"></span>
<a class="u-url" href="http://a">http://a</a>
Expand Down

0 comments on commit 275603f

Please sign in to comment.