aboutsummaryrefslogtreecommitdiff
path: root/rss.py
diff options
context:
space:
mode:
Diffstat (limited to 'rss.py')
-rw-r--r--rss.py14
1 files changed, 12 insertions, 2 deletions
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}><![CDATA[
+{inner}
+]]>
+</{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):