Fix indent output for html/xml

master
pictuga 2020-03-20 12:18:13 +01:00
parent ae3bd58386
commit 5865af64f9
2 changed files with 8 additions and 3 deletions

View File

@ -291,7 +291,7 @@ class ParserXML(ParserBase):
'rssfake': 'http://purl.org/rss/1.0/'}
def parse(self, raw):
parser = etree.XMLParser(recover=True)
parser = etree.XMLParser(recover=True, remove_blank_text=True) # remove_blank_text needed for pretty_print
return etree.fromstring(raw, parser)
def remove(self):
@ -441,7 +441,8 @@ class ParserHTML(ParserXML):
mimetype = ['text/html', 'application/xhtml+xml']
def parse(self, raw):
return lxml.html.fromstring(raw)
parser = etree.HTMLParser(remove_blank_text=True) # remove_blank_text needed for pretty_print
return etree.fromstring(raw, parser)
def tostring(self, encoding='unicode', **k):
return lxml.html.tostring(self.root, encoding=encoding, **k)

View File

@ -448,7 +448,11 @@ def FeedFormat(rss, options):
return rss.tocsv(encoding='UTF-8')
elif options.reader:
return rss.tohtml(encoding='UTF-8')
if options.indent:
return rss.tohtml(encoding='UTF-8', pretty_print=True)
else:
return rss.tohtml(encoding='UTF-8')
else:
if options.indent: