From 35b6905e99dc1c1a0de6364c2c6b543740edd4b4 Mon Sep 17 00:00:00 2001 From: Seth Golub Date: Thu, 7 Mar 2024 09:58:04 -0800 Subject: [PATCH] Support setting entry title type and using it for Atom feeds. --- feedgen/entry.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/feedgen/entry.py b/feedgen/entry.py index 5dd21c2..5d9d7ac 100644 --- a/feedgen/entry.py +++ b/feedgen/entry.py @@ -67,6 +67,7 @@ def __init__(self): # required self.__atom_id = None self.__atom_title = None + self.__atom_title_type = None self.__atom_updated = datetime.now(dateutil.tz.tzutc()) # recommended @@ -106,7 +107,10 @@ def atom_entry(self, extensions=True): raise ValueError('Required fields not set') id = xml_elem('id', entry) id.text = self.__atom_id - title = xml_elem('title', entry) + if self.__atom_title_type is not None: + title = xml_elem('title', entry, type=self.__atom_title_type) + else: + title = xml_elem('title', entry) title.text = self.__atom_title updated = xml_elem('updated', entry) updated.text = self.__atom_updated.isoformat() @@ -260,7 +264,7 @@ def rss_entry(self, extensions=True): return entry - def title(self, title=None): + def title(self, title=None, ttype=None): '''Get or set the title value of the entry. It should contain a human readable title for the entry. Title is mandatory for both ATOM and RSS and should not be blank. @@ -271,6 +275,9 @@ def title(self, title=None): if title is not None: self.__atom_title = title self.__rss_title = title + if ttype not in ('text', 'html', 'xhtml', None): + raise ValueError('title type must be text, html, or xhtml') + self.__atom_title_type = ttype return self.__atom_title def id(self, id=None):