From d952587e33fcebb8f3807a863f2bdd50b86b5b23 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Sun, 23 Nov 2008 18:13:14 -0500 Subject: Fixed rss extension (I think). It throws away any paragraphs before first header, but I think that's what is was trying to do (and failing loadly) before. --- markdown/extensions/rss.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/markdown/extensions/rss.py b/markdown/extensions/rss.py index b7215df..1274da2 100644 --- a/markdown/extensions/rss.py +++ b/markdown/extensions/rss.py @@ -52,7 +52,7 @@ class RssExtension (markdown.Extension): md.xml_mode = True # Insert a tree-processor that would actually add the title tag - treeprocessor = RssTreeProcessor(self) + treeprocessor = RssTreeProcessor(md) treeprocessor.ext = self md.treeprocessors['rss'] = treeprocessor md.stripTopLevelTags = 0 @@ -60,10 +60,6 @@ class RssExtension (markdown.Extension): class RssTreeProcessor(markdown.treeprocessors.Treeprocessor): - def __init__(self, md): - - pass - def run (self, root): rss = etree.Element("rss") @@ -80,34 +76,34 @@ class RssTreeProcessor(markdown.treeprocessors.Treeprocessor): for child in root: - - if child.tag in ["h1", "h2", "h3", "h4", "h5"] : + if child.tag in ["h1", "h2", "h3", "h4", "h5"]: heading = child.text.strip() - item = etree.SubElement(channel, "item") - link = etree.SubElement(item, "link") link.text = self.ext.getConfig("URL") - title = etree.SubElement(item, "title") title.text = heading guid = ''.join([x for x in heading if x.isalnum()]) - guidElem = etree.SubElement(item, "guid") guidElem.text = guid guidElem.set("isPermaLink", "false") - elif child.tag in ["p"] : - if item: + elif child.tag in ["p"]: + try: description = etree.SubElement(item, "description") + except UnboundLocalError: + # Item not defined - moving on + pass + else: if len(child): content = "\n".join([etree.tostring(node) for node in child]) else: content = child.text - pholder = self.stash.store("" % content) + pholder = self.markdown.htmlStash.store( + "" % content) description.text = pholder return rss -- cgit v1.2.3