XML pretty-print in separate option

Who reads plain XML anyway?
master
pictuga 2015-02-20 17:38:39 +08:00
parent fcf4197801
commit ef946c0712
3 changed files with 7 additions and 4 deletions

View File

@ -35,8 +35,7 @@ morss accepts some arguments, to lightly alter the output of morss. Arguments ma
The arguments are: The arguments are:
- Change what morss does - Change what morss does
- `json`: output as JSON - `json`: output as JSON
`indent`: returns indented JSON, takes more place, but human-readable
- `proxy`: doesn't fill the articles - `proxy`: doesn't fill the articles
- `clip`: stick the full article content under the original feed content (useful for twitter) - `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 - `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 - Advanced
- `csv`: export to csv - `csv`: export to csv
- `md`: convert articles to Markdown - `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 - `nolink`: drop links, but keeps links' inner text
- `noref`: drop items' link - `noref`: drop items' link
- `hungry`: grab full-article even if it already looks long enough - `hungry`: grab full-article even if it already looks long enough

View File

@ -361,7 +361,7 @@ class FeedParser(FeedBase):
items = FeedListDescriptor('items') items = FeedListDescriptor('items')
def tostring(self, **k): 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): def tojson(self, indent=None):
return json.dumps(OrderedDict(self), indent=indent) return json.dumps(OrderedDict(self), indent=indent)

View File

@ -631,7 +631,10 @@ def Format(rss, options):
elif options.reader: elif options.reader:
return rss.tohtml() return rss.tohtml()
else: 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): def process(url, cache=None, options=None):