From 292bab155170594932cc397683ba228fbc9791b9 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 9 Dec 2021 16:22:34 +1100 Subject: updated rss - also added a new mpost --- rss.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'rss.py') diff --git a/rss.py b/rss.py index d79f470..8d346ee 100644 --- a/rss.py +++ b/rss.py @@ -47,7 +47,7 @@ def make_post_item(post_html, post_org, post_filename): content = tree.find('.//div[@id="content"]') content.tag = 'description' content.attrib.clear() - post.append(content) + post.append(wrap_in_cdata(content)) etree.SubElement(post, 'link').text = _POSTS_BASE_URL + '/' + post_filename etree.SubElement(post, 'pubDate').text = get_date(post_org) return post @@ -80,6 +80,16 @@ def make_blog_rss(): open(_BLOG_FEED_PATH, 'w').write(etree.tostring(root, encoding='unicode')) return root +def wrap_in_cdata(element): + parser = etree.XMLParser(strip_cdata=False) + inner = ''.join(etree.tostring(child, encoding='unicode') + for child in element) + return etree.XML(f"""<{element.tag}> + +""", parser) + def make_micropost_item(micropost_html): """ The header of a micropost has the following format: @@ -95,7 +105,7 @@ def make_micropost_item(micropost_html): etree.SubElement(micropost, 'title').text = header.find('./b').tail[3:].strip() micropost_html.remove(header) micropost_html.tag = 'description' - micropost.append(micropost_html) + micropost.append(wrap_in_cdata(micropost_html)) return micropost def make_and_add_micropost_items(channel): -- cgit v1.2.3