From ef946c071264110fdd441b87f00175a2b85a5cdf Mon Sep 17 00:00:00 2001 From: pictuga Date: Fri, 20 Feb 2015 17:38:39 +0800 Subject: [PATCH] XML pretty-print in separate option Who reads plain XML anyway? --- README.md | 4 ++-- morss/feeds.py | 2 +- morss/morss.py | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8df85b1..49e8e05 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,7 @@ morss accepts some arguments, to lightly alter the output of morss. Arguments ma The arguments are: - Change what morss does - - `json`: output as JSON - `indent`: returns indented JSON, takes more place, but human-readable + - `json`: output as JSON - `proxy`: doesn't fill the articles - `clip`: stick the full article content under the original feed content (useful for twitter) - `keep`: by default, morss does drop feed description whenever the full-content is found (so as not to mislead users who use Firefox, since the latter only shows the description in the feed preview, so they might believe morss doens't work), but with this argument, the description is kept @@ -44,6 +43,7 @@ The arguments are: - Advanced - `csv`: export to csv - `md`: convert articles to Markdown + - `indent`: returns indented XML or JSON, takes more place, but human-readable - `nolink`: drop links, but keeps links' inner text - `noref`: drop items' link - `hungry`: grab full-article even if it already looks long enough diff --git a/morss/feeds.py b/morss/feeds.py index 3dc6b7e..d73d656 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -361,7 +361,7 @@ class FeedParser(FeedBase): items = FeedListDescriptor('items') def tostring(self, **k): - return etree.tostring(self.xml.getroottree(), pretty_print=True, **k) + return etree.tostring(self.xml.getroottree(), **k) def tojson(self, indent=None): return json.dumps(OrderedDict(self), indent=indent) diff --git a/morss/morss.py b/morss/morss.py index a82c622..f0f4698 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -631,7 +631,10 @@ def Format(rss, options): elif options.reader: return rss.tohtml() else: - return rss.tostring(xml_declaration=True, encoding='UTF-8') + if options.indent: + return rss.tostring(xml_declaration=True, encoding='UTF-8', pretty_print=True) + else: + return rss.tostring(xml_declaration=True, encoding='UTF-8') def process(url, cache=None, options=None):