feeds: ignore provided stylesheets and add ours

Provided sheets usually create errors. Ours is (hopefully) more informative for users not familiar with RSS feeds
master
pictuga 2020-03-20 15:32:44 +01:00
parent 6a01fc439e
commit 4d785820d9
2 changed files with 88 additions and 1 deletions

View File

@ -294,7 +294,7 @@ class ParserXML(ParserBase):
'rssfake': 'http://purl.org/rss/1.0/'} 'rssfake': 'http://purl.org/rss/1.0/'}
def parse(self, raw): 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) return etree.fromstring(raw, parser)
def remove(self): def remove(self):
@ -698,6 +698,10 @@ class FeedXML(Feed, ParserXML):
def tostring(self, encoding='unicode', **k): def tostring(self, encoding='unicode', **k):
# override needed due to "getroottree" inclusion # 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) return etree.tostring(self.root.getroottree(), encoding=encoding, **k)

83
www/sheet.xsl 100644
View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>RSS feed by morss</title>
<style type="text/css">
body > pre {
background-color: #FFFAF4;
padding: 1%;
overflow-x: scroll;
max-width: 100%;
}
ul {
list-style-type: none;
}
.element {
color: darkred;
}
.comment {
color: lightgrey;
}
pre {
margin: 0;
}
</style>
</head>
<body>
<h1>RSS feed by morss</h1>
<p>Your RSS feed is <strong style="color: green">ready</strong>. You
can enter the url of this page in your newsreader.</p>
<ul>
<xsl:apply-templates/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="*">
<li>
<span class="element">
<xsl:value-of select="concat('&lt;', name(), '&gt;')"/>
</span>
<xsl:if test="node()">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:if>
<span class="element">
<xsl:value-of select="concat('&lt;/', name(), '&gt;')"/>
</span>
</li>
</xsl:template>
<xsl:template match="comment()">
<li>
<pre class="comment"><![CDATA[<!--]]><xsl:value-of select="."/><![CDATA[-->]]></pre>
</li>
</xsl:template>
<xsl:template match="text()">
<li>
<pre>
<xsl:value-of select="."/>
</pre>
</li>
</xsl:template>
<xsl:template match="text()[not(normalize-space())]"/>
</xsl:stylesheet>