mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-14 20:50:44 +01:00
RSS: Copy $summary to $description on Atom feeds
Otherwise $description would remain feedparser's default, which is unescaped <content>; but $description is the only usable one on RSS feeds.
This commit is contained in:
parent
04f0d70113
commit
2008088a07
@ -526,6 +526,19 @@ class RSS(callbacks.Plugin):
|
|||||||
if isinstance(item, dict) and 'value' in item:
|
if isinstance(item, dict) and 'value' in item:
|
||||||
value = item['value']
|
value = item['value']
|
||||||
kwargs[key] = value
|
kwargs[key] = value
|
||||||
|
|
||||||
|
for key in ('summary', 'title'):
|
||||||
|
detail = kwargs.get('%s_detail' % key)
|
||||||
|
if isinstance(detail, dict) and detail.get('type') in \
|
||||||
|
('text/html', 'application/xhtml+xml'):
|
||||||
|
kwargs[key] = utils.web.htmlToText(detail['value'])
|
||||||
|
|
||||||
|
if 'description' not in kwargs and kwargs[key]:
|
||||||
|
kwargs['description'] = kwargs[key]
|
||||||
|
|
||||||
|
if 'description' not in kwargs and kwargs.get('content'):
|
||||||
|
kwargs['description'] = kwargs['content']
|
||||||
|
|
||||||
s = string.Template(template).safe_substitute(entry, **kwargs, date=date)
|
s = string.Template(template).safe_substitute(entry, **kwargs, date=date)
|
||||||
return self._normalize_entry(s)
|
return self._normalize_entry(s)
|
||||||
|
|
||||||
|
@ -359,83 +359,91 @@ class RSSTestCase(ChannelPluginTestCase):
|
|||||||
'On the other hand, the refractor\'s')
|
'On the other hand, the refractor\'s')
|
||||||
|
|
||||||
@mock_urllib
|
@mock_urllib
|
||||||
def testContentHtmlOnly(self, mock):
|
def testAtomContentHtmlOnly(self, mock):
|
||||||
timeFastForward(1.1)
|
timeFastForward(1.1)
|
||||||
with conf.supybot.plugins.RSS.format.context('$content'):
|
mock._data = """
|
||||||
mock._data = """
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
||||||
<title>Recent Commits to anope:2.0</title>
|
<title>Recent Commits to anope:2.0</title>
|
||||||
<updated>2023-10-04T16:14:39Z</updated>
|
<updated>2023-10-04T16:14:39Z</updated>
|
||||||
<entry>
|
<entry>
|
||||||
<title>title with <pre>HTML<pre></title>
|
<title>title with <pre>HTML</pre></title>
|
||||||
<updated>2023-10-04T16:14:39Z</updated>
|
<updated>2023-10-04T16:14:39Z</updated>
|
||||||
<content type="html">
|
<content type="html">
|
||||||
content with <pre>HTML<pre>
|
content with <pre>HTML</pre>
|
||||||
</content>
|
</content>
|
||||||
</entry>
|
</entry>
|
||||||
</feed>"""
|
</feed>"""
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$content'):
|
||||||
|
self.assertRegexp('rss https://example.org',
|
||||||
|
'content with HTML')
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$description'):
|
||||||
self.assertRegexp('rss https://example.org',
|
self.assertRegexp('rss https://example.org',
|
||||||
'content with HTML')
|
'content with HTML')
|
||||||
|
|
||||||
@mock_urllib
|
@mock_urllib
|
||||||
def testContentXhtmlOnly(self, mock):
|
def testAtomContentXhtmlOnly(self, mock):
|
||||||
timeFastForward(1.1)
|
timeFastForward(1.1)
|
||||||
with conf.supybot.plugins.RSS.format.context('$content'):
|
mock._data = """
|
||||||
mock._data = """
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
||||||
<title>Recent Commits to anope:2.0</title>
|
<title>Recent Commits to anope:2.0</title>
|
||||||
<updated>2023-10-04T16:14:39Z</updated>
|
<updated>2023-10-04T16:14:39Z</updated>
|
||||||
<entry>
|
<entry>
|
||||||
<title>title with <pre>HTML<pre></title>
|
<title>title with <pre>HTML</pre></title>
|
||||||
<updated>2023-10-04T16:14:39Z</updated>
|
<updated>2023-10-04T16:14:39Z</updated>
|
||||||
<content type="xhtml">
|
<content type="xhtml">
|
||||||
<div xmlns="http://www.w3.org/1999/xhtml">
|
<div xmlns="http://www.w3.org/1999/xhtml">
|
||||||
content with <pre>XHTML<pre>
|
content with <pre>XHTML</pre>
|
||||||
</div>
|
</div>
|
||||||
</content>
|
</content>
|
||||||
</entry>
|
</entry>
|
||||||
</feed>"""
|
</feed>"""
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$content'):
|
||||||
|
self.assertRegexp('rss https://example.org',
|
||||||
|
'content with XHTML')
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$description'):
|
||||||
self.assertRegexp('rss https://example.org',
|
self.assertRegexp('rss https://example.org',
|
||||||
'content with XHTML')
|
'content with XHTML')
|
||||||
|
|
||||||
@mock_urllib
|
@mock_urllib
|
||||||
def testContentHtmlAndPlaintext(self, mock):
|
def testAtomContentHtmlAndPlaintext(self, mock):
|
||||||
timeFastForward(1.1)
|
timeFastForward(1.1)
|
||||||
with conf.supybot.plugins.RSS.format.context('$content'):
|
mock._data = """
|
||||||
mock._data = """
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
||||||
<title>Recent Commits to anope:2.0</title>
|
<title>Recent Commits to anope:2.0</title>
|
||||||
<updated>2023-10-04T16:14:39Z</updated>
|
<updated>2023-10-04T16:14:39Z</updated>
|
||||||
<entry>
|
<entry>
|
||||||
<title>title with <pre>HTML<pre></title>
|
<title>title with <pre>HTML</pre></title>
|
||||||
<updated>2023-10-04T16:14:39Z</updated>
|
<updated>2023-10-04T16:14:39Z</updated>
|
||||||
<!-- Atom spec says multiple contents is invalid, feedparser says it's not.
|
<!-- Atom spec says multiple contents is invalid, feedparser says it's not.
|
||||||
I like having the option, so let's make sure we support it. -->
|
I like having the option, so let's make sure we support it. -->
|
||||||
<content type="html">
|
<content type="html">
|
||||||
content with <pre>HTML<pre>
|
content with <pre>HTML</pre>
|
||||||
</content>
|
</content>
|
||||||
<content type="text">
|
<content type="text">
|
||||||
content with plaintext
|
content with plaintext
|
||||||
</content>
|
</content>
|
||||||
</entry>
|
</entry>
|
||||||
</feed>"""
|
</feed>"""
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$content'):
|
||||||
|
self.assertRegexp('rss https://example.org',
|
||||||
|
'content with plaintext')
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$description'):
|
||||||
self.assertRegexp('rss https://example.org',
|
self.assertRegexp('rss https://example.org',
|
||||||
'content with plaintext')
|
'content with plaintext')
|
||||||
|
|
||||||
@mock_urllib
|
@mock_urllib
|
||||||
def testContentPlaintextAndHtml(self, mock):
|
def testAtomContentPlaintextAndHtml(self, mock):
|
||||||
timeFastForward(1.1)
|
timeFastForward(1.1)
|
||||||
with conf.supybot.plugins.RSS.format.context('$content'):
|
mock._data = """
|
||||||
mock._data = """
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
||||||
<title>Recent Commits to anope:2.0</title>
|
<title>Recent Commits to anope:2.0</title>
|
||||||
<updated>2023-10-04T16:14:39Z</updated>
|
<updated>2023-10-04T16:14:39Z</updated>
|
||||||
<entry>
|
<entry>
|
||||||
<title>title with <pre>HTML<pre></title>
|
<title>title with <pre>HTML</pre></title>
|
||||||
<updated>2023-10-04T16:14:39Z</updated>
|
<updated>2023-10-04T16:14:39Z</updated>
|
||||||
<!-- Atom spec says multiple contents is invalid, feedparser says it's not.
|
<!-- Atom spec says multiple contents is invalid, feedparser says it's not.
|
||||||
I like having the option, so let's make sure we support it. -->
|
I like having the option, so let's make sure we support it. -->
|
||||||
@ -443,12 +451,36 @@ class RSSTestCase(ChannelPluginTestCase):
|
|||||||
content with plaintext
|
content with plaintext
|
||||||
</content>
|
</content>
|
||||||
<content type="html">
|
<content type="html">
|
||||||
content with <pre>HTML<pre>
|
content with <pre>HTML</pre>
|
||||||
</content>
|
</content>
|
||||||
</entry>
|
</entry>
|
||||||
</feed>"""
|
</feed>"""
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$content'):
|
||||||
self.assertRegexp('rss https://example.org',
|
self.assertRegexp('rss https://example.org',
|
||||||
'content with plaintext')
|
'content with plaintext')
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$description'):
|
||||||
|
self.assertRegexp('rss https://example.org',
|
||||||
|
'content with plaintext')
|
||||||
|
|
||||||
|
@mock_urllib
|
||||||
|
def testRssDescriptionHtml(self, mock):
|
||||||
|
timeFastForward(1.1)
|
||||||
|
mock._data = """
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:og="http://ogp.me/ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:schema="http://schema.org/" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>feed title</title>
|
||||||
|
<description/>
|
||||||
|
<language>en</language>
|
||||||
|
<item>
|
||||||
|
<title>title with <pre>HTML</pre></title>
|
||||||
|
<description>description with <pre>HTML</pre></description>
|
||||||
|
</item>
|
||||||
|
</channel>
|
||||||
|
</feed>"""
|
||||||
|
with conf.supybot.plugins.RSS.format.context('$description'):
|
||||||
|
self.assertRegexp('rss https://example.org',
|
||||||
|
'description with HTML')
|
||||||
|
|
||||||
@mock_urllib
|
@mock_urllib
|
||||||
def testFeedAttribute(self, mock):
|
def testFeedAttribute(self, mock):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user