| 61 | class RssTreeProcessor(markdown.treeprocessors.Treeprocessor): |
| 62 | |
| 63 | def run (self, root): |
| 64 | |
| 65 | rss = etree.Element("rss") |
| 66 | rss.set("version", "2.0") |
| 67 | |
| 68 | channel = etree.SubElement(rss, "channel") |
| 69 | |
| 70 | for tag, text in (("title", self.ext.getConfig("TITLE")), |
| 71 | ("link", self.ext.getConfig("URL")), |
| 72 | ("description", None)): |
| 73 | |
| 74 | element = etree.SubElement(channel, tag) |
| 75 | element.text = text |
| 76 | |
| 77 | for child in root: |
| 78 | |
| 79 | if child.tag in ["h1", "h2", "h3", "h4", "h5"]: |
| 80 | |
| 81 | heading = child.text.strip() |
| 82 | item = etree.SubElement(channel, "item") |
| 83 | link = etree.SubElement(item, "link") |
| 84 | link.text = self.ext.getConfig("URL") |
| 85 | title = etree.SubElement(item, "title") |
| 86 | title.text = heading |
| 87 | |
| 88 | guid = ''.join([x for x in heading if x.isalnum()]) |
| 89 | guidElem = etree.SubElement(item, "guid") |
| 90 | guidElem.text = guid |
| 91 | guidElem.set("isPermaLink", "false") |
| 92 | |
| 93 | elif child.tag in ["p"]: |
| 94 | try: |
| 95 | description = etree.SubElement(item, "description") |
| 96 | except UnboundLocalError: |
| 97 | # Item not defined - moving on |
| 98 | pass |
| 99 | else: |
| 100 | if len(child): |
| 101 | content = "\n".join([etree.tostring(node) |
| 102 | for node in child]) |
| 103 | else: |
| 104 | content = child.text |
| 105 | pholder = self.markdown.htmlStash.store( |
| 106 | "<![CDATA[ %s]]>" % content) |
| 107 | description.text = pholder |
| 108 | |
| 109 | return rss |
| 110 | |
| 111 | |
| 112 | def makeExtension(configs): |