From 4d785820d91c4a9e52caab0b22ee5f083fd0b5ab Mon Sep 17 00:00:00 2001 From: pictuga Date: Fri, 20 Mar 2020 15:32:44 +0100 Subject: [PATCH] feeds: ignore provided stylesheets and add ours Provided sheets usually create errors. Ours is (hopefully) more informative for users not familiar with RSS feeds --- morss/feeds.py | 6 +++- www/sheet.xsl | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 www/sheet.xsl diff --git a/morss/feeds.py b/morss/feeds.py index f3f8d46..c6249a3 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -294,7 +294,7 @@ class ParserXML(ParserBase): 'rssfake': 'http://purl.org/rss/1.0/'} def parse(self, raw): - parser = etree.XMLParser(recover=True, remove_blank_text=True) # remove_blank_text needed for pretty_print + parser = etree.XMLParser(recover=True, remove_blank_text=True, remove_pis=True) # remove_blank_text needed for pretty_print return etree.fromstring(raw, parser) def remove(self): @@ -698,6 +698,10 @@ class FeedXML(Feed, ParserXML): def tostring(self, encoding='unicode', **k): # override needed due to "getroottree" inclusion + + if self.root.getprevious() is None: + self.root.addprevious(etree.PI('xml-stylesheet', 'type="text/xsl" href="/sheet.xsl"')) + return etree.tostring(self.root.getroottree(), encoding=encoding, **k) diff --git a/www/sheet.xsl b/www/sheet.xsl new file mode 100644 index 0000000..61b224c --- /dev/null +++ b/www/sheet.xsl @@ -0,0 +1,83 @@ + + + + + + + + + RSS feed by morss + + + + + +

RSS feed by morss

+ +

Your RSS feed is ready. You + can enter the url of this page in your newsreader.

+ +
    + +
+ + + +
+ + +
  • + + + + +
      + +
    +
    + + + +
  • +
    + + +
  • +
    ]]>
    +
  • +
    + + +
  • +
    +				
    +			
    +
  • +
    + + + +